G
Guest
Can someone tell me what is wrong with the sub below???
I'm try to create a bunch of SQL connections on the fly...
I'm sure there is a better way to do this but was having problem with the
sql statement in the Stored Procedure so I decided to try this way...
If anyone can give me a hand with this I would really appritiate it!
Thanks
.....
Exception Details: System.InvalidOperationException: ExecuteNonQuery:
Connection property has not been initialized.
Source Error:
Line 94: cmd.ExecuteNonQuery()
=============CODE===========
For i As Integer = 1 To 10
Dim MyConn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand
Dim varSQL As String
Dim varMenuValue As String
Dim varPriceValue As String
varSQL = "varSQL" & i.ToString()
varMenuValue = "varMenuValue" & i.ToString()
varPriceValue = "varPriceValue" & i.ToString()
varMenuValue = CType(Page.FindControl("tbMenuItem" &
i.ToString()), TextBox).Text
varPriceValue = CType(Page.FindControl("tbMenuItem" &
i.ToString()), TextBox).Text
varSQL = "UPDATE tblRestaurant SET menuitem" & i.ToString() &
"=" & varMenuValue & ", priceitem" & i.ToString() & "=" & varPriceValue & "
WHERE ItemID =" & i.ToString
cmd.CommandText = varSQL
cmd.CommandType = CommandType.Text
MyConn.Open()
cmd.ExecuteNonQuery()
MyConn.Close()
Next
I'm try to create a bunch of SQL connections on the fly...
I'm sure there is a better way to do this but was having problem with the
sql statement in the Stored Procedure so I decided to try this way...
If anyone can give me a hand with this I would really appritiate it!
Thanks
.....
Exception Details: System.InvalidOperationException: ExecuteNonQuery:
Connection property has not been initialized.
Source Error:
Line 94: cmd.ExecuteNonQuery()
=============CODE===========
For i As Integer = 1 To 10
Dim MyConn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand
Dim varSQL As String
Dim varMenuValue As String
Dim varPriceValue As String
varSQL = "varSQL" & i.ToString()
varMenuValue = "varMenuValue" & i.ToString()
varPriceValue = "varPriceValue" & i.ToString()
varMenuValue = CType(Page.FindControl("tbMenuItem" &
i.ToString()), TextBox).Text
varPriceValue = CType(Page.FindControl("tbMenuItem" &
i.ToString()), TextBox).Text
varSQL = "UPDATE tblRestaurant SET menuitem" & i.ToString() &
"=" & varMenuValue & ", priceitem" & i.ToString() & "=" & varPriceValue & "
WHERE ItemID =" & i.ToString
cmd.CommandText = varSQL
cmd.CommandType = CommandType.Text
MyConn.Open()
cmd.ExecuteNonQuery()
MyConn.Close()
Next