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
This blog is about my history as a software engineer utilizing technologies C#, Java, React, JavaScript, .NET Core, SQL Server , Oracle, 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 my ADVERTISING links to help support this blog. Thank you.
Tuesday, March 19, 2013
Using Statement to get 1 Scalar Value back from SQL
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment