Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having a dataset with a data table having predefined column namely

Id,Name,DOB,Designation,Mobile,Mail,Salary


How to fill the data table with particular columns on particular record
Posted
Comments
Jafarinejadvazifehkhorani 30-Jun-14 9:27am    
it's not clear, add more info if you want us to help you
KUMAR619 1-Jul-14 0:43am    
I want to use typed dataset to display values in datagridview

1 solution

I think I misunderstood the question a little.
If you want to add a row to a data table you can do like this.

C#
DataSet ds; // your predefined dataset
DataTable dt = ds.Tables[0];
or
DataTable dt = ds.Tables["MyTable"];

dt.Rows.Add(1, "Harry Hacker", "DOB", "Programmer", "123456789", "harry.hacker@codeville.com", "$1");

or

DataRow dr = dt.Rows.New();
dr["Id"] = 1;
dr["Name"] = "Harry Hacker";
dr["DOB"] = "What ever this means";
dr["Designation"] = "Programmer";
dr["Mobile"] = "123456789";
dr["Mail"] = "harry.hacker@codeville.com";
dr["Salary"] = "$1";
dt.Rows.Add(dr);


If you have a DataGridView called dgView you can add the DataSet as the data source.

dgView.DataSource = ds;
dgView.DataMember = "MyTable";



My first answer, not maybe on target.
C#
foreach (DataRow dr in dt.Rows)
{
   dr["Id"] = some_value;
   dr["Name"] = some_other_value;
   etc.
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900