B
Bob
Hi,
i wrote code for inserting data into a table, but it runs twice. If i remove
the line: "comd.ExecuteNonQuery()", then it runs once; but i thought that
line was necessary for executing the sql command ... if i remove "
oConnection.Open()", then error: "connection is not open".
see my code:
Dim oConnection As SqlConnection
Dim comd As SqlCommand
Dim sConnectionString As String
Dim sql, na As String
Dim iden As Integer
sConnectionString =
ConfigurationManager.ConnectionStrings("myconn").ConnectionString.ToString()
sql = "INSERT INTO table(...) VALUES (...);"
oConnection = New SqlConnection(sConnectionString)
comd = New SqlCommand(sql, oConnection)
comd.Parameters.Add("@var1", SqlDbType.NVarChar, 10).value="ok"
oConnection.Open()
comd.ExecuteNonQuery()
Thanks
Bob
i wrote code for inserting data into a table, but it runs twice. If i remove
the line: "comd.ExecuteNonQuery()", then it runs once; but i thought that
line was necessary for executing the sql command ... if i remove "
oConnection.Open()", then error: "connection is not open".
see my code:
Dim oConnection As SqlConnection
Dim comd As SqlCommand
Dim sConnectionString As String
Dim sql, na As String
Dim iden As Integer
sConnectionString =
ConfigurationManager.ConnectionStrings("myconn").ConnectionString.ToString()
sql = "INSERT INTO table(...) VALUES (...);"
oConnection = New SqlConnection(sConnectionString)
comd = New SqlCommand(sql, oConnection)
comd.Parameters.Add("@var1", SqlDbType.NVarChar, 10).value="ok"
oConnection.Open()
comd.ExecuteNonQuery()
Thanks
Bob