Hello there, I am new to .NET environment. And have been struggling with this datagrid. i always seem to have these errors
Line 1: Incorrect syntax near '='.
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: Line 1: Incorrect syntax near '='.
Source Error:
Line 235: ' execute the command
Line 236: SqlConnection1.Open()
Line 237: DeleteCommand.ExecuteNonQuery()
Line 238: SqlConnection1.Close()
Line 239:
Source File: c:\inetpub\ Line: 237
Stack Trace:
[SqlException: Line 1: Incorrect syntax near '='.]
System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
Assigment.admin.DataGrid1_DeleteCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\ System.Web.UI.WebControls.DataGrid.OnDeleteCommand(DataGridCommandEventArgs e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
this is the piece of code
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
StatusLabel.Text = "Deleted was pressed"
Dim keycolumn As Integer = 1
' gives us the actual data value of the key field of the current row
Dim keyvalue As String = e.Item.Cells(keycolumn).Text
StatusLabel.Text = "Delete was pressed on row " + e.Item.Cells(keycolumn).Text
SqlCommand1.CommandText = "Delete "
Dim DeleteCommand As New SqlCommand("DELETE FROM links WHERE id =" & keyvalue, SqlConnection1)
' execute the command
SqlConnection1.Open()
DeleteCommand.ExecuteNonQuery()
SqlConnection1.Close()
' rebind the grid
DataGrid1.CurrentPageIndex = 0
DataGrid1.EditItemIndex = -1
BindGrid()
End Sub
Thanks
Line 1: Incorrect syntax near '='.
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: Line 1: Incorrect syntax near '='.
Source Error:
Line 235: ' execute the command
Line 236: SqlConnection1.Open()
Line 237: DeleteCommand.ExecuteNonQuery()
Line 238: SqlConnection1.Close()
Line 239:
Source File: c:\inetpub\ Line: 237
Stack Trace:
[SqlException: Line 1: Incorrect syntax near '='.]
System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
Assigment.admin.DataGrid1_DeleteCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\ System.Web.UI.WebControls.DataGrid.OnDeleteCommand(DataGridCommandEventArgs e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
this is the piece of code
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
StatusLabel.Text = "Deleted was pressed"
Dim keycolumn As Integer = 1
' gives us the actual data value of the key field of the current row
Dim keyvalue As String = e.Item.Cells(keycolumn).Text
StatusLabel.Text = "Delete was pressed on row " + e.Item.Cells(keycolumn).Text
SqlCommand1.CommandText = "Delete "
Dim DeleteCommand As New SqlCommand("DELETE FROM links WHERE id =" & keyvalue, SqlConnection1)
' execute the command
SqlConnection1.Open()
DeleteCommand.ExecuteNonQuery()
SqlConnection1.Close()
' rebind the grid
DataGrid1.CurrentPageIndex = 0
DataGrid1.EditItemIndex = -1
BindGrid()
End Sub
Thanks