在做仓库管理系统时,我想用一个界面显示,入库主表和入库明细表里的数据,当单击主表一条记录时显示对应记录的明细表,我看到了微软给出的解决方案,代码如下
dataGridView1.DataSource = bs_EntryBillMaster; // DataGridView 显示
dataGridView2.DataSource = bs_EntryBillDetail;
//this.editorGrid1.DataSource=ds.Tables[0];
String connectionString = "Persist Security Info=False;Integrated Security=true;Initial Catalog=IMSDB;Server=(LOCAL)";
SqlConnection connection = new SqlConnection(connectionString); DataSet dbSet = new DataSet(); // 创建数据集
using (SqlDataAdapter da = new SqlDataAdapter("select * from IMS_Flow_EntryBillMaster", connection))
{
da.Fill(dbSet, "IMS_Flow_EntryBillMaster"); // 填充一个 Customers 表
}
using (SqlDataAdapter da = new SqlDataAdapter("select * from IMS_Flow_EntryBillDetail", connection))
{
da.Fill(dbSet, "IMS_Flow_EntryBillDetail");
// 填充一个 Orders 表
}
// ##说明:上面是Northwind库表创建程序,文后附加的代码可以取代上述功能
DataColumn parentCol = dbSet.Tables["IMS_Flow_EntryBillMaster"].Columns["BillNo"];
DataColumn childCol = dbSet.Tables["IMS_Flow_EntryBillDetail"].Columns["BillNo"];
DataRelation relation = new DataRelation("FK_IMS_Flow_EntryBillDetail", parentCol, childCol);
dbSet.Relations.Add(relation); // 添加主从关系到数据集中 bs_EntryBillMaster.DataSource = dbSet;
bs_EntryBillMaster.DataMember = "IMS_Flow_EntryBillMaster"; // 绑定到数据源——主表
bs_EntryBillDetail.DataSource = bs_EntryBillMaster;
红色部分出现错误,也就是表关系出错,我查了所有可能都没解决,有热心的朋友能想到错在哪里吗?
dataGridView1.DataSource = bs_EntryBillMaster; // DataGridView 显示
dataGridView2.DataSource = bs_EntryBillDetail;
//this.editorGrid1.DataSource=ds.Tables[0];
String connectionString = "Persist Security Info=False;Integrated Security=true;Initial Catalog=IMSDB;Server=(LOCAL)";
SqlConnection connection = new SqlConnection(connectionString); DataSet dbSet = new DataSet(); // 创建数据集
using (SqlDataAdapter da = new SqlDataAdapter("select * from IMS_Flow_EntryBillMaster", connection))
{
da.Fill(dbSet, "IMS_Flow_EntryBillMaster"); // 填充一个 Customers 表
}
using (SqlDataAdapter da = new SqlDataAdapter("select * from IMS_Flow_EntryBillDetail", connection))
{
da.Fill(dbSet, "IMS_Flow_EntryBillDetail");
// 填充一个 Orders 表
}
// ##说明:上面是Northwind库表创建程序,文后附加的代码可以取代上述功能
DataColumn parentCol = dbSet.Tables["IMS_Flow_EntryBillMaster"].Columns["BillNo"];
DataColumn childCol = dbSet.Tables["IMS_Flow_EntryBillDetail"].Columns["BillNo"];
DataRelation relation = new DataRelation("FK_IMS_Flow_EntryBillDetail", parentCol, childCol);
dbSet.Relations.Add(relation); // 添加主从关系到数据集中 bs_EntryBillMaster.DataSource = dbSet;
bs_EntryBillMaster.DataMember = "IMS_Flow_EntryBillMaster"; // 绑定到数据源——主表
bs_EntryBillDetail.DataSource = bs_EntryBillMaster;
红色部分出现错误,也就是表关系出错,我查了所有可能都没解决,有热心的朋友能想到错在哪里吗?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货