R
riaz.hasani
Hi every1, I'm having problem with datagrid updates.
When I click on update I receive an error. Which I'm unable to trace.
I'm posting the code & error.
Any help would be appreciated.
Code
*******************************************************************
Sub dgdSearch_Update(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
'Read in the values of the updated row
Dim DemoNumber As Integer =
dgdSearch.DataKeys(e.Item.ItemIndex)
'Dim strCustomerName As String =
CType(e.Item.Cells(1).Controls(0), TextBox).Text
'Dim strCustomerNumber As String =
CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim strSerialNumber As String =
CType(e.Item.Cells(3).Controls(0), TextBox).Text
'Dim strModelNumber As String =
CType(e.Item.Cells(4).Controls(0), TextBox).Text
'Dim strRMANumber As String =
CType(e.Item.Cells(5).Controls(0), TextBox).Text
'Dim strConditionNumber As String =
CType(e.Item.Cells(6).Controls(0), TextBox).Text
'Dim strLocationNumber As String =
CType(e.Item.Cells(7).Controls(0), TextBox).Text
Dim strStatus As String = CType(e.Item.Cells(8).Controls(0),
TextBox).Text
'Dim strRevisedDate As Date =
CType(e.Item.Cells(9).Controls(0), TextBox).Text
Dim strNote As String
If TypeOf (e.Item.Cells(10).Controls(0)) Is TextBox Then
strNote = CType(e.Item.Cells(10).Controls(0), TextBox).Text
End If
'Construct the SQL statement using Parameters
Dim strSQL As String = "UPDATE [Equip] SET [SerialNumber] =
@SerialNumber, " & _
"[Status] = @Status, [Note] = @Note " &
_
"WHERE [DemoNumber] = @DemoNumber"
' Create Instance of Connection and Command Object
'1. Create a connection
Const strConnString As String = ("server=(local);Integrated
Security=SSPI;database=Equipment Log")
Dim objConn As New SqlConnection(strConnString)
objConn.Open()
Dim myCommand As SqlCommand = New SqlCommand(strSQL, objConn)
myCommand.CommandType = CommandType.Text
' Add Parameters to the SQL query
Dim parameterDemoNumber As SqlParameter = New
SqlParameter("@DemoNumber", SqlDbType.Int, 4)
parameterDemoNumber.Value = DemoNumber
myCommand.Parameters.Add(parameterDemoNumber)
Dim parameterSerialNumber As SqlParameter = New
SqlParameter("@SerialNumber", SqlDbType.VarChar, 10)
parameterSerialNumber.Value = strSerialNumber
myCommand.Parameters.Add(parameterSerialNumber)
Dim parameterStatus As SqlParameter = New
SqlParameter("@Status", SqlDbType.VarChar, 10)
parameterStatus.Value = strStatus
myCommand.Parameters.Add(parameterStatus)
Dim parameterNote As SqlParameter = New SqlParameter("@Note",
SqlDbType.VarChar, 500)
parameterNote.IsNullable = True
parameterNote.Value = strNote
myCommand.Parameters.Add(parameterNote)
'Execute the UPDATE query
myCommand.ExecuteNonQuery()
objConn.Close()
'Finally, set the EditItemIndex to -1 and rebind the DataGrid
dgdSearch.EditItemIndex = -1
BindData()
'refresh the datagrid
dgdSearch.DataBind()
End Sub
*******************************************************************
Error
Prepared statement '(@SerialNumber varchar(10),@Status
varchar(10),@Note varchar(500' expects parameter @Note, which was not
supplied.
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.SqlClient.SqlException: Prepared
statement '(@SerialNumber varchar(10),@Status varchar(10),@Note
varchar(500' expects parameter @Note, which was not supplied.
Source Error:
Line 400: myCommand.Parameters.Add(parameterDemoNumber)
Line 401:
Line 402: myCommand.ExecuteNonQuery() 'Execute the UPDATE
query
Line 403:
Line 404: objConn.Close()
Source File: c:\inetpub\wwwroot\Demo Equip Log\Search Equipment.aspx.vb
Line: 402
Stack Trace:
[SqlException: Prepared statement '(@SerialNumber varchar(10),@Status
varchar(10),@Note varchar(500' expects parameter @Note, which was not
supplied.]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +742
System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
Demo_Equip_Log.Search_Equipment.dgdSearch_Update(Object sender,
DataGridCommandEventArgs e) in c:\inetpub\wwwroot\Demo Equip Log\Search
Equipment.aspx.vb:402
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs
e) +109
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source,
EventArgs e) +507
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args) +26
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e) +106
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args) +26
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
+120
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+138
System.Web.UI.Page.ProcessRequestMain() +1292
When I click on update I receive an error. Which I'm unable to trace.
I'm posting the code & error.
Any help would be appreciated.
Code
*******************************************************************
Sub dgdSearch_Update(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
'Read in the values of the updated row
Dim DemoNumber As Integer =
dgdSearch.DataKeys(e.Item.ItemIndex)
'Dim strCustomerName As String =
CType(e.Item.Cells(1).Controls(0), TextBox).Text
'Dim strCustomerNumber As String =
CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim strSerialNumber As String =
CType(e.Item.Cells(3).Controls(0), TextBox).Text
'Dim strModelNumber As String =
CType(e.Item.Cells(4).Controls(0), TextBox).Text
'Dim strRMANumber As String =
CType(e.Item.Cells(5).Controls(0), TextBox).Text
'Dim strConditionNumber As String =
CType(e.Item.Cells(6).Controls(0), TextBox).Text
'Dim strLocationNumber As String =
CType(e.Item.Cells(7).Controls(0), TextBox).Text
Dim strStatus As String = CType(e.Item.Cells(8).Controls(0),
TextBox).Text
'Dim strRevisedDate As Date =
CType(e.Item.Cells(9).Controls(0), TextBox).Text
Dim strNote As String
If TypeOf (e.Item.Cells(10).Controls(0)) Is TextBox Then
strNote = CType(e.Item.Cells(10).Controls(0), TextBox).Text
End If
'Construct the SQL statement using Parameters
Dim strSQL As String = "UPDATE [Equip] SET [SerialNumber] =
@SerialNumber, " & _
"[Status] = @Status, [Note] = @Note " &
_
"WHERE [DemoNumber] = @DemoNumber"
' Create Instance of Connection and Command Object
'1. Create a connection
Const strConnString As String = ("server=(local);Integrated
Security=SSPI;database=Equipment Log")
Dim objConn As New SqlConnection(strConnString)
objConn.Open()
Dim myCommand As SqlCommand = New SqlCommand(strSQL, objConn)
myCommand.CommandType = CommandType.Text
' Add Parameters to the SQL query
Dim parameterDemoNumber As SqlParameter = New
SqlParameter("@DemoNumber", SqlDbType.Int, 4)
parameterDemoNumber.Value = DemoNumber
myCommand.Parameters.Add(parameterDemoNumber)
Dim parameterSerialNumber As SqlParameter = New
SqlParameter("@SerialNumber", SqlDbType.VarChar, 10)
parameterSerialNumber.Value = strSerialNumber
myCommand.Parameters.Add(parameterSerialNumber)
Dim parameterStatus As SqlParameter = New
SqlParameter("@Status", SqlDbType.VarChar, 10)
parameterStatus.Value = strStatus
myCommand.Parameters.Add(parameterStatus)
Dim parameterNote As SqlParameter = New SqlParameter("@Note",
SqlDbType.VarChar, 500)
parameterNote.IsNullable = True
parameterNote.Value = strNote
myCommand.Parameters.Add(parameterNote)
'Execute the UPDATE query
myCommand.ExecuteNonQuery()
objConn.Close()
'Finally, set the EditItemIndex to -1 and rebind the DataGrid
dgdSearch.EditItemIndex = -1
BindData()
'refresh the datagrid
dgdSearch.DataBind()
End Sub
*******************************************************************
Error
Prepared statement '(@SerialNumber varchar(10),@Status
varchar(10),@Note varchar(500' expects parameter @Note, which was not
supplied.
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.SqlClient.SqlException: Prepared
statement '(@SerialNumber varchar(10),@Status varchar(10),@Note
varchar(500' expects parameter @Note, which was not supplied.
Source Error:
Line 400: myCommand.Parameters.Add(parameterDemoNumber)
Line 401:
Line 402: myCommand.ExecuteNonQuery() 'Execute the UPDATE
query
Line 403:
Line 404: objConn.Close()
Source File: c:\inetpub\wwwroot\Demo Equip Log\Search Equipment.aspx.vb
Line: 402
Stack Trace:
[SqlException: Prepared statement '(@SerialNumber varchar(10),@Status
varchar(10),@Note varchar(500' expects parameter @Note, which was not
supplied.]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +742
System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
Demo_Equip_Log.Search_Equipment.dgdSearch_Update(Object sender,
DataGridCommandEventArgs e) in c:\inetpub\wwwroot\Demo Equip Log\Search
Equipment.aspx.vb:402
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs
e) +109
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source,
EventArgs e) +507
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args) +26
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e) +106
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args) +26
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
+120
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+138
System.Web.UI.Page.ProcessRequestMain() +1292