SqlConnection conn = new SqlConnection();
SqlConnectionStringBuilder ssb = new SqlConnectionStringBuilder();
conn.ConnectionString = "Persist Security Info=False;Integrated Security=true;Initial Catalog=IMSDB;Server=(LOCAL);";
conn.Open();
DataSet dbSet = new DataSet(); // 创建数据集
using (SqlDataAdapter da = new SqlDataAdapter("select * from IMS_Flow_EntryBillMaster", conn))
{
da.Fill(dbSet, "EntryBillMaster"); // 填充一个 Customers 表
}
using (SqlDataAdapter da = new SqlDataAdapter("select * from IMS_Flow_EntryBillDetail", conn))
{
da.Fill(dbSet, "EntryBillDetail");
// 填充一个 Orders 表
}
// ##说明:上面是Northwind库表创建程序,文后附加的代码可以取代上述功能
DataColumn parentCol = dbSet.Tables["EntryBillMaster"].Columns["BillNo"];
DataColumn childCol = dbSet.Tables["EntryBillDetail"].Columns["BillNo"];
DataRelation relation = new DataRelation("FK_IMS_Flow_EntryBillDetail_IMS_Flow_EntryBillDetail", parentCol, childCol);
dbSet.Relations.Add(relation); // 添加主从关系到数据集中
BindingSource bs_EntryBillMaster = new BindingSource(); // 创建绑定源
BindingSource bs_EntryBillDetail = new BindingSource();
bs_EntryBillMaster.DataSource = dbSet;
bs_EntryBillMaster.DataMember = "EntryBillMaster"; // 绑定到数据源——主表
bs_EntryBillDetail.DataSource = bs_EntryBillMaster;
bs_EntryBillDetail.DataMember = "FK_IMS_Flow_EntryBillDetail_IMS_Flow_EntryBillDetail"; // 绑定到关系——从表,注意:区分大小写
dataGridView1.DataSource = bs_EntryBillMaster; // DataGridView 显示
dataGridView2.DataSource = bs_EntryBillDetail;
运行到红色字体就自动跳出程序了,为什么啊,错在哪里啊,帮忙看看
SqlConnectionStringBuilder ssb = new SqlConnectionStringBuilder();
conn.ConnectionString = "Persist Security Info=False;Integrated Security=true;Initial Catalog=IMSDB;Server=(LOCAL);";
conn.Open();
DataSet dbSet = new DataSet(); // 创建数据集
using (SqlDataAdapter da = new SqlDataAdapter("select * from IMS_Flow_EntryBillMaster", conn))
{
da.Fill(dbSet, "EntryBillMaster"); // 填充一个 Customers 表
}
using (SqlDataAdapter da = new SqlDataAdapter("select * from IMS_Flow_EntryBillDetail", conn))
{
da.Fill(dbSet, "EntryBillDetail");
// 填充一个 Orders 表
}
// ##说明:上面是Northwind库表创建程序,文后附加的代码可以取代上述功能
DataColumn parentCol = dbSet.Tables["EntryBillMaster"].Columns["BillNo"];
DataColumn childCol = dbSet.Tables["EntryBillDetail"].Columns["BillNo"];
DataRelation relation = new DataRelation("FK_IMS_Flow_EntryBillDetail_IMS_Flow_EntryBillDetail", parentCol, childCol);
dbSet.Relations.Add(relation); // 添加主从关系到数据集中
BindingSource bs_EntryBillMaster = new BindingSource(); // 创建绑定源
BindingSource bs_EntryBillDetail = new BindingSource();
bs_EntryBillMaster.DataSource = dbSet;
bs_EntryBillMaster.DataMember = "EntryBillMaster"; // 绑定到数据源——主表
bs_EntryBillDetail.DataSource = bs_EntryBillMaster;
bs_EntryBillDetail.DataMember = "FK_IMS_Flow_EntryBillDetail_IMS_Flow_EntryBillDetail"; // 绑定到关系——从表,注意:区分大小写
dataGridView1.DataSource = bs_EntryBillMaster; // DataGridView 显示
dataGridView2.DataSource = bs_EntryBillDetail;
运行到红色字体就自动跳出程序了,为什么啊,错在哪里啊,帮忙看看
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货