473,473 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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

Nov 17 '05 #1
4 59292
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

Nov 17 '05 #2
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

Aamir wrote:
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


Nov 17 '05 #3
Sorry Its Item property not column... you can use index also...

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

Regards
Aamir

Nov 17 '05 #4
Hai Aamir...
ya its working fine...

Thanx for ur immediate response...

bye...

Regards,
Prince

Aamir wrote:
Sorry Its Item property not column... you can use index also...

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

Regards
Aamir


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
1
by: Abareblue | last post by:
I have no clue on how to insert a record into access. here is the whole thing using System; using System.Drawing; using System.Collections; using System.ComponentModel;
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
5
by: robecflo | last post by:
Hi Forum, i have a problem, hope somebody can give me ideas. I'm developing with windows forms and vb.net, and oracle as a database. At this moment i have a table called amortizaciones, this table...
5
by: Brad Baker | last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL database. At the top of the page I have the following code: <%@ Page Language="C#" Debug="true" %> <%@ import...
1
by: Magnus | last post by:
My situation compares to this: I have two tables parentTable(id, foreignId) and childTable(id, value). "foreignId" in the "parentTable" references "id" in "childTable". The constraint is by default...
0
by: magnolia | last post by:
i created a trigger that will record the changes made to a table .everything works fine except the insert query.whenerever i try to insert a record it fires insert and update triger at the same time...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.