c# DataRelations 问题

来源:百度知道 编辑:UC知道 时间:2024/05/30 11:10:26
未将对象引用设置到对象的实例
vs.net2003
SqlDataAdapter thisAdapter = new SqlDataAdapter("select * from customers", conn);
SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
DataSet ds = new DataSet();

SqlDataAdapter cusAdapter = new SqlDataAdapter("select * from customers", conn);
SqlDataAdapter orderAdapter = new SqlDataAdapter("select * from orders", conn);
cusAdapter.Fill(ds, "customers");
orderAdapter.Fill(ds, "customers");
//DataRelation custOrderRel = ds.Relations.Add("CustOrders",
DataRelation custOrderRel = new DataRelation("CustOrders",
ds.Tables["customers"].Columns["customerId"],
ds.Tables["orders"].Columns["customerId"]);
ds.Relations.Add(custOrderRel);

foreach(DataRow custRow in ds.Tables["customers"].Rows)
{
Console.WriteLine("CustomerId:&q

你的两次填充为什么都使用customer表名啊?代码结构不太好啊。还有最后是想利用关系吗?视图dataview可以更方便嘛。

至少要告诉我哪行出错了呀