How to Insert,Update and Delete a record into DataTable?

  • Thread starter Thread starter Prince
  • Start date Start date
P

Prince

Hi All,

Can anyone tell me how to Insert,Update and Delete a record into
already existing DataTable?

Looking forward for the reply...

Thanx in advance...

Regards,
Prince
 
Hi

To insert recorde you will have to create a DataRow object and append
it to the data table...

For Eg

DataRow myRow;
myRow = myDataTable.NewRow();
myRow.Columns["Col1"].Value = "Abc";
myRow.Columns["Col2"].Value = "Xyz";
myDataTable.Rows.Add(myRow);

To update datatable

myDataTable.Rows[0]["Col1"].value = "abc..."; //Thats enough;

To delete from datatable

myDataTable.Rows.RemoveAt(2);

or

myDataTable.Rows.Remove(myRow);

Hope this is helpfull

Thanx
Aamir
 
Hi Aamir,

Thanx for ur reply and it is useful for me...
but in the below statement
myRow.Columns["Col1"].Value = "Abc";

I think Columns is not applicable bcoz when when I keep dot
after
myRow, I am not able to see the Columns...

Looking forward for ur reply...

Regards,
Prince
 
Sorry Its Item property not column... you can use index also...

myRow.Item["Col1"] = value;
or
myRow["Col1"] = value;

Regards
Aamir
 
Hai Aamir...


ya its working fine...

Thanx for ur immediate response...

bye...

Regards,
Prince
 

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