ado.net datacolumn

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!
 
M

Marc Gravell

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
 

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

Top