Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: datagrid update - don't understand why not working.


Message #1 by sg48@y... on Thu, 31 Oct 2002 04:02:09
Am getting error message : Must declare the variable '@s...'
I am using code that is similar to examples where sql parameter is not 
declared. I've included my Sub dgEvents_Update code as well as the error 
message and trace results

Code snippet From my code behind page
*****************************************

    Sub dgEvents_Update(ByVal sender As System.Object, ByVal e As 
DataGridCommandEventArgs)

        Dim iEventID As Integer = e.Item.Cells(1).Text
        Dim strSponsor As String = CType(e.Item.Cells(10).Controls(0),  
TextBox).Text


        Dim strSQL As String
        strSQL = "UPDATE tblEvents SET sponsor = @sponsor WHERE eventid = 
@eventid"

        Dim DBConn As OleDbConnection
        DBConn = New OleDbConnection( _
          "PROVIDER=SQLOLEDB;DATA SOURCE=209.23.44.6;User 
ID=eventpop_sa;Password=Qvc2b9RL;DATABASE=eventpop")
        DBConn.Open()
        Dim myCommand As OleDbCommand = New OleDbCommand(strSQL, DBConn)
        myCommand.CommandType = CommandType.Text
        'Add Parameters to the SQL Query

        Dim parameterSponsor As OleDbParameter = New OleDbParameter
("@sponsor", OleDbType.Char, 10)
        parameterSponsor.Value = strSponsor
        myCommand.Parameters.Add(parameterSponsor)

        Dim parameterEventID As OleDbParameter = New OleDbParameter
("@eventid", OleDbType.Integer)
        parameterEventID.Value = iEventID
        myCommand.Parameters.Add(parameterEventID)

        myCommand.ExecuteNonQuery()
        DBConn.Close()
        dgEvents.EditItemIndex = -1
        BindDataGrid()
    End Sub

End Class
*****************************************
Error message and trace


Must declare the variable '@s...'. 
Description: An unhandled exception occurred during the execution of the 
current web request. Please review the stack trace for more information 
about the error and where it originated in the code. 

Exception Details: System.Data.OleDb.OleDbException: Must declare the 
variable '@s...'.

Source Error: 


Line 80:         myCommand.Parameters.Add(parameterEventID)
Line 81: 
Line 82:         myCommand.ExecuteNonQuery()
Line 83:         DBConn.Close()
Line 84:         dgEvents.EditItemIndex = -1
 

Source File: C:\Inetpub\wwwroot\eventpop\admin_events.aspx.vb    Line: 82 

Stack Trace: 


[OleDbException (0x80040e14): Must declare the variable '@s...'.]
   System.Data.OleDb.OleDbDataReader.NextResults(IMultipleResults 
imultipleResults, OleDbConnection connection, OleDbCommand command) +283
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior 
behavior, String method) +557
   System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +54
   eventpop.admin_events.dgEvents_Update(Object sender, 
DataGridCommandEventArgs e) in 
C:\Inetpub\wwwroot\eventpop\admin_events.aspx.vb:82
   System.Web.UI.WebControls.DataGrid.OnUpdateCommand
(DataGridCommandEventArgs e) +109
   System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, 
EventArgs e) +748
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) 
+26
   System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, 
EventArgs e) +100
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) 
+26
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +121
   
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaiseP
ostBackEvent(String eventArgument) +115
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler 
sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1263

 

  Return to Index