Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: UPDATE Command in .NET


Message #1 by steveproctor@c... on Sun, 2 Jun 2002 23:52:21
I continue to have problems with the Update Command in .NET.  The error 
message is:

System.Data.OleDb.OleDbException: Syntax error in UPDATE statement.

Using an Access database, below is the code.

Sub dlstRM_UpdateCommand( s As Object, e As DataListCommandEventArgs )
	Dim Conn As OleDbConnection
	Dim strUpdate As String
	Dim cmdUpdate as OleDbCommand
	Dim strForm As String 'This is the key field
	Dim txtInitials As TextBox
	Dim txtDate As TextBox 'This is a date value
	Dim txtAmount As TextBox 'This is a dollar amount.
	'All the values below are strings.
	Dim txtTo As TextBox
	Dim txtForm As TextBox
	Dim txtCust As TextBox
	Dim txtName As TextBox
	Dim txtFile As TextBox
	
	strForm = dlstRM.DataKeys( e.Item.ItemIndex )
	 txtInitials = e.Item.FindControl( "txtInitials" )
	 txtDate = e.Item.FindControl( "txtDate" )
	 txtAmount = e.Item.FindControl( "txtAmount" )
	 txtTo = e.Item.FindControl( "txtTo" )
	 txtCust = e.Item.FindControl( "txtCust" )
	 txtName = e.Item.FindControl( "txtName" )
	 txtFile = e.Item.FindControl( "txtFile" )
	 
	 'I establish the connection here.
	strUpdate = "Update TABLE Set Initials=@Initials, Date=@Date, 
Amount=@Amount, To=@To, Cust=@Cust, Name=@Name, File=@File Where 
Form=@Form"
		
	cmdUpdate = New OleDbCommand( strUpdate, Conn )
	cmdUpdate.Parameters.Add( "@Form", strForm )
	cmdUpdate.Parameters.Add( "@Initials", txtInitials.Text )
	cmdUpdate.Parameters.Add( "@Date", txtDate.Text )
	cmdUpdate.Parameters.Add( "@Amount", txtAmount.Text )
	cmdUpdate.Parameters.Add( "@To", txtTo.Text )
	cmdUpdate.Parameters.Add( "@Cust", txtCust.Text )
	cmdUpdate.Parameters.Add( "@Name", txtName.Text )
	cmdUpdate.Parameters.Add( "@File", txtFile.Text )
	
	Conn.Open
	cmdUpdate.ExecuteNonQuery()
	Conn.Close()
	dlstRM.EditItemIndex = -1
	BindDataList
End Sub

I'm wondering if the problem is the data types.  I've checked the syntax 
over & over and I can't find anything wrong.  Any help is greatly 
appreciated.

Steve
Message #2 by "Sri Vidya" <svsvidya@i...> on Mon, 03 Jun 2002 09:50:58 +0530
Hi,

    I think, you have not specified the connection string. Something 
like

    conn = new OleDbConnection( connection string parameters ) 

Shouldn't there be one? I may be wrong. I have not worked much with 
OleDbConnection.

Cheers,
Vidya.






On Sun, 2 Jun 2002 23:52:21
  steveproctor@c... wrote:
>I continue to have problems with the Update Command in .NET.  The 
>error 
>message is:
>
>System.Data.OleDb.OleDbException: Syntax error in UPDATE statement.
>
>Using an Access database, below is the code.
>
>Sub dlstRM_UpdateCommand( s As Object, e As DataListCommandEventArgs 
>)
>	Dim Conn As OleDbConnection
>	Dim strUpdate As String
>	Dim cmdUpdate as OleDbCommand
>	Dim strForm As String 'This is the key field
>	Dim txtInitials As TextBox
>	Dim txtDate As TextBox 'This is a date value
>	Dim txtAmount As TextBox 'This is a dollar amount.
>	'All the values below are strings.
>	Dim txtTo As TextBox
>	Dim txtForm As TextBox
>	Dim txtCust As TextBox
>	Dim txtName As TextBox
>	Dim txtFile As TextBox
>	
>	strForm = dlstRM.DataKeys( e.Item.ItemIndex )
>	 txtInitials = e.Item.FindControl( "txtInitials" )
>	 txtDate = e.Item.FindControl( "txtDate" )
>	 txtAmount = e.Item.FindControl( "txtAmount" )
>	 txtTo = e.Item.FindControl( "txtTo" )
>	 txtCust = e.Item.FindControl( "txtCust" )
>	 txtName = e.Item.FindControl( "txtName" )
>	 txtFile = e.Item.FindControl( "txtFile" )
>	 
>	 'I establish the connection here.
>	strUpdate = "Update TABLE Set Initials=@Initials, Date=@Date, 
>Amount=@Amount, To=@To, Cust=@Cust, Name=@Name, File=@File Where 
>Form=@Form"
>		
>	cmdUpdate = New OleDbCommand( strUpdate, Conn )
>	cmdUpdate.Parameters.Add( "@Form", strForm )
>	cmdUpdate.Parameters.Add( "@Initials", txtInitials.Text )
>	cmdUpdate.Parameters.Add( "@Date", txtDate.Text )
>	cmdUpdate.Parameters.Add( "@Amount", txtAmount.Text )
>	cmdUpdate.Parameters.Add( "@To", txtTo.Text )
>	cmdUpdate.Parameters.Add( "@Cust", txtCust.Text )
>	cmdUpdate.Parameters.Add( "@Name", txtName.Text )
>	cmdUpdate.Parameters.Add( "@File", txtFile.Text )
>	
>	Conn.Open
>	cmdUpdate.ExecuteNonQuery()
>	Conn.Close()
>	dlstRM.EditItemIndex = -1
>	BindDataList
>End Sub
>
>I'm wondering if the problem is the data types.  I've checked the 
>syntax 
>over & over and I can't find anything wrong.  Any help is greatly 
>appreciated.
>
>Steve

---------------------------------------------
http://mail.indiainfo.com
India's first ISO certified portal
Check world time at http://time.indiainfo.com
Message #3 by steveproctor@c... on Mon, 3 Jun 2002 23:48:31
Dear Vidya,

Thanks for your message.  I did not include the connection string in the 
code snippet.  I'm reading the database, so I don't think the connection 
is the problem.

Steve
> Hi,

    I think, you have not specified the connection string. Something 
like

    conn = new OleDbConnection( connection string parameters ) 

Shouldn't there be one? I may be wrong. I have not worked much with 
OleDbConnection.

Cheers,
Vidya.






On Sun, 2 Jun 2002 23:52:21
  steveproctor@c... wrote:
>I continue to have problems with the Update Command in .NET.  The 
>error 
>message is:
>
>System.Data.OleDb.OleDbException: Syntax error in UPDATE statement.
>
>Using an Access database, below is the code.
>
>Sub dlstRM_UpdateCommand( s As Object, e As DataListCommandEventArgs 
>)
>	Dim Conn As OleDbConnection
>	Dim strUpdate As String
>	Dim cmdUpdate as OleDbCommand
>	Dim strForm As String 'This is the key field
>	Dim txtInitials As TextBox
>	Dim txtDate As TextBox 'This is a date value
>	Dim txtAmount As TextBox 'This is a dollar amount.
>	'All the values below are strings.
>	Dim txtTo As TextBox
>	Dim txtForm As TextBox
>	Dim txtCust As TextBox
>	Dim txtName As TextBox
>	Dim txtFile As TextBox
>	
>	strForm = dlstRM.DataKeys( e.Item.ItemIndex )
>	 txtInitials = e.Item.FindControl( "txtInitials" )
>	 txtDate = e.Item.FindControl( "txtDate" )
>	 txtAmount = e.Item.FindControl( "txtAmount" )
>	 txtTo = e.Item.FindControl( "txtTo" )
>	 txtCust = e.Item.FindControl( "txtCust" )
>	 txtName = e.Item.FindControl( "txtName" )
>	 txtFile = e.Item.FindControl( "txtFile" )
>	 
>	 'I establish the connection here.
>	strUpdate = "Update TABLE Set Initials=@Initials, Date=@Date, 
>Amount=@Amount, To=@To, Cust=@Cust, Name=@Name, File=@File Where 
>Form=@Form"
>		
>	cmdUpdate = New OleDbCommand( strUpdate, Conn )
>	cmdUpdate.Parameters.Add( "@Form", strForm )
>	cmdUpdate.Parameters.Add( "@Initials", txtInitials.Text )
>	cmdUpdate.Parameters.Add( "@Date", txtDate.Text )
>	cmdUpdate.Parameters.Add( "@Amount", txtAmount.Text )
>	cmdUpdate.Parameters.Add( "@To", txtTo.Text )
>	cmdUpdate.Parameters.Add( "@Cust", txtCust.Text )
>	cmdUpdate.Parameters.Add( "@Name", txtName.Text )
>	cmdUpdate.Parameters.Add( "@File", txtFile.Text )
>	
>	Conn.Open
>	cmdUpdate.ExecuteNonQuery()
>	Conn.Close()
>	dlstRM.EditItemIndex = -1
>	BindDataList
>End Sub
>
>I'm wondering if the problem is the data types.  I've checked the 
>syntax 
>over & over and I can't find anything wrong.  Any help is greatly 
>appreciated.
>
>Steve

---------------------------------------------
http://mail.indiainfo.com
India's first ISO certified portal
Check world time at http://time.indiainfo.com

  Return to Index