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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

updating DataGrids

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
I am getting the following error when I try to update a record in a datagrid. I am new to ASP.NET and this is a tutorial I am going through. I have never seen the error before so I don't know how to trouble shoot it.


Incorrect syntax near 'Stevens'.
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 'Stevens'.

Source Error:


Line 46: myCommand = new SqlCommand(strUpdateStmt, myConnection)
Line 47: myConnection.open()
Line 48: myCommand.ExecuteNonQuery()
Line 49:
Line 50: personInfo.EditItemIndex = -1


Source File: E:\Intranet\Mystuff\aspnet\tryaspnet.aspx Line: 48

Stack Trace:


[SqlException: Line 1: Incorrect syntax near 'Stevens'.]
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +192
ASP.tryaspnet_aspx.DataGrid_Update(Object Source, DataGridCommandEventArgs E) in E:\Intranet\Mystuff\aspnet\tryaspnet.aspx:48
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) +106
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121
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() +1263


 
I forgot to put my code that I am using

Public Sub DataGrid_Update(Source As Object, E As DataGridCommandEventArgs)
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim txtName As Textbox = E.Item.Cells(2).Controls(0)
Dim txtAddress As Textbox = E.Item.Cells(3).Controls(0)
Dim strUpdateStmt As String

strUpdateStmt = "UPDATE Person SET Name = " & txtName.Text & " Address = " & txtAddress.Text & " WHERE ID = " & E.Item.Cells(1).Text

myConnection = New SqlConnection("server=AM1ST_FS1;database=HRINFO;uid=sa")
myCommand = new SqlCommand(strUpdateStmt, myConnection)
myConnection.open()
myCommand.ExecuteNonQuery()

personInfo.EditItemIndex = -1
BindData()
End Sub
 
please print us out the sql statement... it's a sql error and it refers to something in the sql statement.

 
thy this:

strUpdateStmt = "UPDATE Person SET Name = '" & txtName.Text & "' Address = '" & txtAddress.Text & "' WHERE ID = " & E.Item.Cells(1).Text

hth

 
you have forgotten a comma. You need one after each set statement that has another following it.


strUpdateStmt = "UPDATE Person SET Name = " & txtName.text & ", Address = & txtAddress.text & "WHERE ID = " & E.Item.Cells(1).Text


That should fix it I think. [peace]
 
haha Thnx. It comes from having twitchy fingers gotta keep looking for the simple mistakes. [peace]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top