Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Using Update and Insert Commands in DataList


Message #1 by steveproctor@c... on Sun, 9 Jun 2002 03:42:10
I continue to have trouble with Insert and Update Commands in ASP.NET 
using a DataList.  This is happening in all the programs I have tried.  So 
I'm stalled until I can get the syntax right.  Can anyone help?

The syntax I have been using is as follows:

Sub dlstTable1_UpdateCommand(s As Object, e As DataListCommandEventArgs)
	'Here I declare variables.  I don't think this is the problem.
	
	strForm = dlstRMChecks.DataKeys( e.Item.ItemIndex )
	 txtInitials = e.Item.FindControl( "txtInitials" )
	' txtDate = e.Item.FindControl( "txtDate" ) [I COMMENTED THESE OUT 
TO AVOID DATE AND AMOUNT FIELDS]
	 'txtAmount = e.Item.FindControl( "txtAmount" )
	 txtTo = e.Item.FindControl( "txtTo" )
	 txtForm = e.Item.FindControl( "txtForm" )
	 txtClient = e.Item.FindControl( "txtClient" )
	 txtAlien = e.Item.FindControl( "txtAlien" )
	 txtFile = e.Item.FindControl( "txtFile" )
	 
	 COMMENT:  Here I place the connection.  I'm connecting to the 
database, so this is not the problem.
	 
	 THIS IS THE PROBLEM.  IT'S SOMEWHERE IN THE UPDATE SQL COMMAND.
	strUpdate = "Update Table1 Set Initials=@Initials, To=@To, 
Client=@Client, Alien=@Alien, File=@File Where Form=txtForm"
	
	I get the following error message.
	
	Exception Details: System.Data.OleDb.OleDbException: Syntax error 
in UPDATE statement.

Source Error: 


Line 102:	
Line 103:	Conn.Open
Line 104:	cmdUpdate.ExecuteNonQuery()
Line 105:	Conn.Close()
Line 106:	dlstTable1.EditItemIndex = -1

When I use tracing for the code, I get the following:

Update Table1 Set Initials=@Initials, To=@To, Client=@Client, 
Alien=@Alien, File=@File Where Form=txtForm 

I'm totally at a loss.  None of my other programs that use INSERT and 
UPDATE work either.  ASP.NET seems very peculiar when interpreting SQL 
statements.  Can anyone help on this?  Thanks.

Steve
Message #2 by Colin.Montgomery@C... on Wed, 12 Jun 2002 08:53:13 -0400
strUpdate = "Update Table1 Set Initials=@Initials, To=@To, 
Client=@Client, Alien=@Alien, File=@File Where Form=txtForm"

When you execute this, the following is passed to the DB engine: (as shown
by your trace)
Update Table1 Set Initials=@Initials, To=@To, Client=@Client, 
Alien=@Alien, File=@File Where Form=txtForm 

You actually want to pass the values contained in the @xxx parameters into
the SQL statement before it's executed:

strUpdate = "Update Table1 Set Initials=" & @Initials & ", To=" & @To & ",
Client=" _
		& @Client & ", Alien=" & @Alien, File=" & @File & " Where
Form=" & txtForm

Otherwise you're just passing your DB engine the values "@Initials" etc.

HTH,
Col


*******

This message and any attachment are confidential and may be privileged or otherwise protected from disclosure.  If you are not the
intended recipient, please telephone or email the sender and delete this message and any attachment from your system.  If you are
not the intended recipient you must not copy this message or attachment or disclose the contents to any other person.

For further information about Clifford Chance please see our website at http://www.cliffordchance.com or refer to any Clifford
Chance office.

  Return to Index