OdbcDataAdapter.UpdateCommand without OdbcCommand.Parameters?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to perform an update on a database using the OdbcDataAdapter
without adding any parameters to an OdbcCommand? I've found an article on
MSDN and it says you need to have some OdbcCommand.Parameters and an
OdbcParameter. Is it not possible to perform an update without going through
all this? Why couldn't I just do...

odbcCommand("UPDATE blah SET foo = "Hello" WHERE blahID = "1");?
odbcDataAdapter.UpdateCommand = odbcCommand;

The thing that's making me question this is because in the article it says
you need to have OdbcDataAdapter.Parameters for a select statement too and in
my program I didn't have them. I literally just did...

odbcCommand("SELECT * from blah");
odbcDataAdapter.SelectCommand = odbcCommand;

Darrell
 
Hi,

If you are doing updates directly on databaes (no source, such as DataTable,
involved) then just create an instance of OdbcCommand, set its CommandText
and Connection parameters and fire up ExecuteNonQuery method.
Otherwise (DataTable) you'll need parameters.
Btw, even in the first case, the use of parameters is recommended (agains
concatenating sql command) to avoid sql injection attacks.
 
Miha is correct.

The DataAdapter's updating commands are designed to submit pending
changes from a DataTable to your data store. If that's the scenario you
want to handle, describe your updating logic as parameterized queries. You
"bind" the parameters to the desired columns in your DataTable and specify
the version of the column value to use - either the current or original
value. When you call Update, the DataAdapter walks through the rows, finds
the ones with pending changes, selects the appropriate Command to execute,
pushes values into the parameters based on the "bindings" you've specified,
and executes that Command.

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2005 Microsoft Corporation. All rights reserved.
 
Back
Top