PC Review


Reply
Thread Tools Rate Thread

ado.net updatecommand

 
 
LC
Guest
Posts: n/a
 
      26th Jul 2005
Ok...I give up.

I am coding my own ole data adapter. I have a table called "Savings"
which I am updating via a datagrid. I have the following code to set
up my update command:

-----------------------
// Setup Savings
//Update
uCmd =
new OleDbCommand("UPDATE Savings SET "
+ "[Description]=@Description,"
+ "Amount=@Amount "
+ "WHERE (TransDate=@TransDate)");

uCmd.Parameters.Add("@Description",
System.Data.OleDb.OleDbType.VarChar, 100, "Description");
uCmd.Parameters.Add("@Amount", System.Data.OleDb.OleDbType.Currency,
4, "Amount");
uCmd.Parameters.Add("@TransDate", System.Data.OleDb.OleDbType.Date,
0, "@TransDate");

oleDbDataAdapter1.UpdateCommand = uCmd;
------------------------------------------

If I update a row in the datagrid and hit Update the database will be
updated but every row in the database table is updated. Doesn't look
like the system is using my where clause. I have 2 rows in the table
and transdate is the primary key. If I have 7/01/05 and 7/02/05 rows
and I update only the 7/01/05 row, the change is made to both rows.

Can someone please point in the correct direction here?

Thanks

 
Reply With Quote
 
 
 
 
LC
Guest
Posts: n/a
 
      27th Jul 2005
I think I fixed it. I removed the Where Clause. I gather if you are
using a datagrid you don't need the where clause. I guess you would
use a where clause if you were updating a row(s) in a database that the
parameter was coming in from a textbox or listbox or something like
that....correct?

I still don't understand though by having the where clause in the
Update statement why all the rows in the database got update with the
same single change.

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
UpdateCommand =?Utf-8?B?R3VkbmkgRy4gU2lndXJkc3Nvbg==?= Microsoft ADO .NET 1 10th Jul 2007 05:21 PM
updatecommand wandii Microsoft VB .NET 5 15th May 2006 07:13 PM
Updatecommand Sam Microsoft ADO .NET 0 29th Oct 2005 08:12 PM
UpdateCommand Peter W Johnson Microsoft VB .NET 5 4th May 2005 03:14 PM
UpdateCommand André Almeida Maldonado Microsoft ASP .NET 1 15th Jan 2004 02:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:35 AM.