Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to ASP.NET

Status
Not open for further replies.

jurelmo

Programmer
May 5, 2005
5
0
0
GB
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
 
Check to see you if you are getting a value or your keyvalue variable, perhaps you are not getting one and the SQL statement is just "DELETE FROM links WHERE id ="
 

jurelmo ,

put single quotes before and after keyvalue(string value).


Dim DeleteCommand As New SqlCommand("DELETE FROM links WHERE id ='" & keyvalue & "'", SqlConnection1)

Hope it will solve ur problem if else ignore it.

thanks,

Vijay kumar T.
 
Hello Vijay

Thank You for the reply. Ive tried the code you gave me but gives another error.

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 237: DeleteCommand.ExecuteNonQuery()
Line 238: SqlConnection1.Close()
Line 239:
Line 240: ' rebind the grid
Line 241: DataGrid1.CurrentPageIndex = 0


Source File: c:\inetpub\ Line: 239

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()
 
Hi jbenson001

Thank you for your reply. Unfortunatelly it did not worked.
Gave an error


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 237: DeleteCommand.ExecuteNonQuery()
Line 238: SqlConnection1.Close()
Line 239:
Line 240: ' rebind the grid
Line 241: DataGrid1.CurrentPageIndex = 0


Source File: c:\inetpub\ Line: 239

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()
 
Try this...do you get something to print out?
Code:
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand

   Dim keycolumn As Integer = 1
   Dim keyvalue As String = e.Item.Cells(keycolumn).Text
   Response.Write(keyvalue)
End Sub

or try to specify this..
Code:
Dim DeleteCommand As New SqlCommand("DELETE FROM links WHERE id =" & keyvalue, SqlConnection1)
deleteCommand.commandType = CommandType.Text

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Maybe Dim keycolumn As Integer = 1 should be Dim keycolumn As Integer = 0

Is your "keycolumn" the first column in your grid? Things are zero based around here :)
 
maybe the value is empty, can u output the sql and see???

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top