Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want to insert a value 11 in all the column of specific row.


suppose I want to insert this value in first row like
dt.Tables[0].Rows[1]



can anyone please provide the code?
Posted
Comments
Vedat Ozan Oner 18-Jun-14 5:21am    
this link contains all information you need: http://msdn.microsoft.com/en-us/library/tzwewss0%28v=vs.110%29.aspx

First of all, the first row of table is present at index [0] so the code should be as following to access first row of data table.

C#
// Considering that "dt" is an object of DataTable
dt.Rows[0]


Please find below the code to insert same value i.e. "11" in all columns of first row in datatable

C#
foreach (DataColumn col in dt.Columns)
{
  dt.Rows[0][col.ColumnName] = "11";
}


Happy Coding :)
 
Share this answer
 
dt.Rows[0][0] = "Hello World";
 
Share this answer
 
You can loop using columns collection.

C#
foreach(DataColumn column in table.Columns)
        {
            //access each row column by specifying row[column];
            
        }
 
Share this answer
 

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