Executing an insert Command from the Connection object

  • Thread starter Thread starter lilush
  • Start date Start date
L

lilush

Hello,
i have a project where every time i want to add or update
something in the DB i use the datatable and dataadpter
and i build an insert sql command or an update sql
command to the dataadapter and then use the update.
i want to know if i can execute the command i make
directly through the connection object (oledb) and not
create the datatable and dataadapter
thank u
 
You don't have to use a datatable and dataadapter but you
do need more than just the OleDbConnection object. You
could try using the OleDbCommand object instead.

// -- Start Code Example
string ConnectionString
= "Provider=Microsoft.Jet ..etc..";
OleDbConnection conn = new OleDbConnection
(ConnectionString);
OleDbCommand comm = new OleDbCommand();
comm.CommandText = "INSERT INTO ..etc..";
comm.Connection = conn;
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
// -- End Code Example


HTH

Sam
 
Hi,

You can execute DML statements without having to create
datatable and dataadapter. You can create the
OleDbCommand/SqlCommand object based on the database and
execute the command.

DataAdapter is basically used to fill the dataset and
update the database based on the changes which are done
to the dataset.

The following link explains of how to work with command
object.

http://samples.gotdotnet.com/quickstart/howto/doc/adoplus/
ExecuteCommand.aspx

Regards,
Madhu

MVP | MCSD.NET
 
Back
Top