I want to return the value of Identity Key which in this case is an AutoNumber field in my table and place the value of that field of the newly added record into a textbox. Here's what I got so far, my insert works, but no return as of yet:
Protected Sub Button2_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles Button2.Click
Dim sql As New SqlCommand
'Dim myconn As Data.SqlClient. SqlConnection
Dim mycmd As Data.SqlClient. SqlCommand
Dim ResultReader As SqlDataReader
Dim result As String
Dim mySqlConnection As SqlConnection = New SqlConnection(C onfigurationMan ager.Connection Strings("MAS_XC MConnectionStri ng").Connection String)
mySqlConnection .Open()
result = ""
ResultReader = Nothing
mycmd = New SqlCommand("SEL ECT * FROM CA_IT_STORYBOOK ", mySqlConnection )
mycmd.CommandTe xt = "INSERT INTO CA_IT_STORYBOOK (SalesOrderNumb er, InvoiceNumber, StoryBook) VALUES (012,334,'NewTe st3');Select @OutVar = SCOPE_IDENTITY( )"
mycmd.ExecuteNo nQuery()
' mycmd.ExecuteSc alar()
If ResultReader.Ha sRows Then
result = result & vbCrLf & ResultReader.It em(0).ToString( )
TextBox1.Text = result
End If
mySqlConnection .Close()
End Sub
Protected Sub Button2_Click(B yVal sender As Object, ByVal e As System.EventArg s) Handles Button2.Click
Dim sql As New SqlCommand
'Dim myconn As Data.SqlClient. SqlConnection
Dim mycmd As Data.SqlClient. SqlCommand
Dim ResultReader As SqlDataReader
Dim result As String
Dim mySqlConnection As SqlConnection = New SqlConnection(C onfigurationMan ager.Connection Strings("MAS_XC MConnectionStri ng").Connection String)
mySqlConnection .Open()
result = ""
ResultReader = Nothing
mycmd = New SqlCommand("SEL ECT * FROM CA_IT_STORYBOOK ", mySqlConnection )
mycmd.CommandTe xt = "INSERT INTO CA_IT_STORYBOOK (SalesOrderNumb er, InvoiceNumber, StoryBook) VALUES (012,334,'NewTe st3');Select @OutVar = SCOPE_IDENTITY( )"
mycmd.ExecuteNo nQuery()
' mycmd.ExecuteSc alar()
If ResultReader.Ha sRows Then
result = result & vbCrLf & ResultReader.It em(0).ToString( )
TextBox1.Text = result
End If
mySqlConnection .Close()
End Sub
Comment