各位大哥,大姐
你们好!本人做了用c#主从关系录入界面主表用textbox录入明细表用datagrid
测试代码如下
string connectionString="server=COMPUTER;uid=sa;pwd=mylove;database=test";
mySqlConnection=new System.Data.SqlClient.SqlConnection(connectionString);
mySqlConnection.Open();
myDataSet=new DataSet();
myDataTable=new DataTable();
myDataSet.EnforceConstraints=false;
myDataSet.CaseSensitive=true;
mySqlCommand=new SqlCommand();
mySqlCommand.Connection=mySqlConnection;
mySqlCommand.CommandText="select * from a1";
sqlDataAdapter=new SqlDataAdapter();
sqlDataAdapter.SelectCommand=mySqlCommand;
sqlDataAdapter.TableMappings.Add("Table","a1");
sqlDataAdapter.Fill(myDataSet);
DmySqlCommand=new SqlCommand();
DmySqlCommand.Connection=mySqlConnection;
DmySqlCommand.CommandText="select * from a2";
sqlDataAdapter1=new SqlDataAdapter();
sqlDataAdapter1.SelectCommand=DmySqlCommand;
sqlDataAdapter1.TableMappings.Add("Table","a2");
sqlDataAdapter1.Fill(myDataSet);
System.Data.DataRelation dataRelation;
System.Data.DataColumn dataColumn1;
System.Data.DataColumn dataColumn2;
dataColumn1=myDataSet.Tables["a1"].Columns["customer_name"];
dataColumn2=myDataSet.Tables["a2"].Columns["customer_name"];
dataRelation=new DataRelation("kk",dataColumn1,dataColumn2);
myDataSet.Relations.Add(dataRelation);
this.textBox1.DataBindings.Add("Text",myDataSet.Tables["a1"],"customer_name");
dataGrid1.DataSource=myDataSet.Tables["a1"];
dataGrid1.DataMember="kk";
cm=(CurrencyManager)this.BindingContext[myDataSet.Tables["a1"]];
myDataTable=myDataSet.Tables["a1"];
BmOrders = this.BindingContext[myDataSet, "a1"];
BmOrderDetails = this.BindingContext[myDataSet, "a2"];
这是form1.loadr 的代码
我在datagrid中录入数据不行录入一笔在录入下一笔时上一笔消失请各位大哥,大姐帮忙