Public Function AddProductCategory( _ ByVal newName As String, ByVal connString As String) As Integer Dim newProdID As Int32 = 0 Dim sql As String = _ "INSERT INTO Production.ProductCategory (Name) VALUES (@Name); " _ & "SELECT CAST(scope_identity() AS int);" Using conn As New SqlConnection(connString) Dim cmd As New SqlCommand(sql, conn) cmd.Parameters.Add("@Name", SqlDbType.VarChar) cmd.Parameters("@Name").Value = newName Try conn.Open() newProdID = Convert.ToInt32(cmd.ExecuteScalar()) Catch ex As Exception Console.WriteLine(ex.Message) End Try End Using Return newProdID End Function
Robert Dannelly blog, Over the internet you can find me by "robert dannelly blog". The blog is an ongoing blog of my software engineering over technologies C#, VB.NET, Java, React, JavaScript, .NET Core Current, SQL Server 7 - Current Version, GIT, GitHub, Jira, Azure, AWS and HTML5. “I have not failed. I've just found 10,000 ways that won't work.” Thomas A. Edison, please click on all links to help support this blog. Thank you. “As an Amazon Associate, I earn from qualifying purchases.”
Tuesday, March 19, 2013
Using Statement to get 1 Scalar Value back from SQL
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment