P
Patrick Olurotimi Ige
I'm trying to insert data in Page_load below but its inserting 2 records
at the sametime!!!
What am i doing wrong!!!!!
Sub Page_Load (ByVal sender As System.Object, ByVal e As
System.EventArgs)Handles MyBase.Load
if Not Page.IsPostBack then
Dim strLogonUsr As String
strLogonUsr = Request.ServerVariables("LOGON_USER")
Dim myConnection = New
SqlConnection("server=(local);database=Wintergreen;integrated
security=true;")
Dim insertCmd As String = _
"insert into survey values (@username, @DateCreated);"
' Initialize the SqlCommand with the new SQL string.
Dim myCommand = New SqlCommand(insertCmd, myConnection)
' Created new parameters for the SqlCommand object and
' initialize them to the field values.
' Create the parameter for the logon user
myCommand.Parameters.Add(New SqlParameter("@username", _
SqlDbType.VarChar, 50))
' Assigned the value
myCommand.Parameters("@username").Value = strLogonUsr
' Created the parameter for the time
myCommand.Parameters.Add(New SqlParameter("@DateCreated", _
SqlDbType.DateTime, 8))
' Assign the value as Now()
myCommand.Parameters("@DateCreated").Value = Now()
myCommand.Connection.Open()
'myCommand.ExecuteNonQuery()
Try
' Execute the command
'myCommand.ExecuteNonQuery()
myCommand.ExecuteNonQuery()
' Report success
Label1.Text = "Thanks for filling Crazy John's Survey!"
Catch exc As SqlException
' Report error if u have one
Label1.Text = exc.Message
Finally
' Close the connection no matter what
myCommand.Connection.Close()
End Try
End If
End Sub
at the sametime!!!
What am i doing wrong!!!!!
Sub Page_Load (ByVal sender As System.Object, ByVal e As
System.EventArgs)Handles MyBase.Load
if Not Page.IsPostBack then
Dim strLogonUsr As String
strLogonUsr = Request.ServerVariables("LOGON_USER")
Dim myConnection = New
SqlConnection("server=(local);database=Wintergreen;integrated
security=true;")
Dim insertCmd As String = _
"insert into survey values (@username, @DateCreated);"
' Initialize the SqlCommand with the new SQL string.
Dim myCommand = New SqlCommand(insertCmd, myConnection)
' Created new parameters for the SqlCommand object and
' initialize them to the field values.
' Create the parameter for the logon user
myCommand.Parameters.Add(New SqlParameter("@username", _
SqlDbType.VarChar, 50))
' Assigned the value
myCommand.Parameters("@username").Value = strLogonUsr
' Created the parameter for the time
myCommand.Parameters.Add(New SqlParameter("@DateCreated", _
SqlDbType.DateTime, 8))
' Assign the value as Now()
myCommand.Parameters("@DateCreated").Value = Now()
myCommand.Connection.Open()
'myCommand.ExecuteNonQuery()
Try
' Execute the command
'myCommand.ExecuteNonQuery()
myCommand.ExecuteNonQuery()
' Report success
Label1.Text = "Thanks for filling Crazy John's Survey!"
Catch exc As SqlException
' Report error if u have one
Label1.Text = exc.Message
Finally
' Close the connection no matter what
myCommand.Connection.Close()
End Try
End If
End Sub