ado.net datacolumn

  • Thread starter Thread starter gigs
  • Start date Start date
G

gigs

string strConn, strSQL;
strConn = @"Data Source=Gigs-PC;Initial Catalog=Northwind;Integrated
Security=True;";
strSQL = "SELECT OrderID, CustomerID FROM Orders";

SqlDataAdapter da = new SqlDataAdapter(strSQL, strConn);
DataSet ds = new DataSet();
DataTable tbl = ds.Tables.Add("Customers");
DataColumn col = tbl.Columns.Add("CustomerID");
DataColumn col1 = tbl.Columns.Add("OrderID");
DataRow row = tbl.Rows.Add("10");
DataRow row1 = tbl.Rows.Add("11");
DataRow row2 = col1.Table.Rows.Add("11");

foreach (DataRow roww in tbl.Rows)
Console.WriteLine(roww["CustomerID"]);

foreach (DataRow roww in tbl.Rows)
Console.WriteLine(roww["OrderID"]);


How I can add rows to OrderID column? Why is this code only adding rows to
CustomerID?



thanks!
 
The Add method takes a "params" array of values. Add the values for each
column as so:

..Rows.Add("123","456");

where 123 goes in the first column (of the new row), and "456" into the
second.

Marc
 
Back
Top