ado.net updatecommand

  • Thread starter Thread starter LC
  • Start date Start date
L

LC

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
 
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.
 
Back
Top