AddNew method

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

I am fairly new to ADO.NET, is there an ADO.NET method that
is similar to the AddNew method that existed in ADO for adding new
records to a database.

Martin
 
Martin said:
I am fairly new to ADO.NET, is there an ADO.NET method that
is similar to the AddNew method that existed in ADO for adding new
records to a database.

Martin
Like Calvin mentions, the .AddNew Method of the dataTable will do it for
you.

DataRow dro = dataTableName.NewRow();
or Dim dro as DataRow = dataTableName.NewRow

at this point, you have a new row with the schema defs of the table, so if
the table had 4 columns, your datarow has 4 columns with the same names,
types etc. BUT it's not added to the datatable yet.

So, you can set the values of each field now or wait until you add it to the
row(usually waiting is a bad idea b/c you'll invariably violate an integrity
rule at some point or even if you don't, forget to set those values).

dataTableName.Rows.Add(dro);
or dataTableName.Rows.Add(dro) (who says VB.NET and C# are that much
differerent ;-) ).

HTH,

Bill



--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top