running an SQL statement directly from C#

  • Thread starter Thread starter John Viele
  • Start date Start date
Like John mentioned, you'll need a CommandObject and
you'll want to use ExecuteNonQuery Method.

Basically, you need to have a valid and open connection...

After that, you'll want to declare a command and
associate the connection with it. You'll want to
add "INSERT INTO MyTable (Field1, Field2) Values
('one', 'two');

Then you want to call command.ExecuteNonQuery();

Then you'll want to close your connection and dispose of
whatever objects you don't need. There's a .RowsAffected
property that will tell you how many rows were affected
by your update.

It'd probably be helpful to take a step back and get
familiar with ADO.NET as a whole. David Sceppa's Book
ADO.NET Core Reference by David Sceppa is a wonderful
resource. Bill Vaughn has some wonderful articles out
there as well in publications like
www.hardcorevisualbasic.net.

If you have a specific problem, write back and we can
hopefully get you through it.

Cheers,

Bill


W.G. Ryan
(e-mail address removed)
www.knowdotnet.com
 
Back
Top