Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myConnection As New SqlConnection("Connection String Here")
myConnection.Open()
Dim myTrans = myConnection.BeginTransaction()
Dim myCommand As New SqlCommand()
myCommand.Connection = myConnection
myCommand.Transaction = myTrans
Try
myCommand.CommandText = "INSERT INTO Calendar (ModuleID, UserID, Field1, Field2, Field3, Field4) VALUES (ModuleId,UserID,1,1,1,1)"
myCommand.ExecuteNonQuery()
myTrans.Commit()
Me.Response.Text = "Records have been written successfully to database."
Catch ep As Exception
myTrans.Rollback()
'Response.Write(ep.ToString())
Me.Response.Text = "No records where written to database."
Finally
myConnection.Close()
End Try
End Sub
============================================================================
The 1,1,1 values store fine, but the ModuleID & UserID storing as zero, also in these variations of code:
- VALUES (Me.ModuleID, Me.UserID etc...
- VALUES (ModuleID, UserID etc...
- VALUES (" Me.ModuleID ", " Me.UserID " etc...
- VALUES (" ModuleID ", " UserID " etc...
- VALUES ( ' " + Me.ModuleID + " ', ' " + Me.UserID + " ' etc...
- VALUES ( ' " + ModuleID + " ', ' " + UserID + " ' etc...
.ToString() as well ????
I have also added the texboxes to the .ascx file, as mentioned in the first post.
They should bind he ModuleId & UserID, and I am not sure if I need them or not.
What should the VALUES input be to store correctly within SQL statement?