日期:2014-05-18  浏览次数:20691 次

ado.net的问题
string ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa ;Password=sa ;Initial Catalog=test1;Data Source=192.168.10.250";
  System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection(ConnectionString);
  cn.Open();
  System.Data.DataSet ds = new System.Data.DataSet();
  System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter("SELECT * From a11 ;SELECT * From b11", cn);

  System.Data.OleDb.OleDbCommandBuilder cb = new System.Data.OleDb.OleDbCommandBuilder(da);  
  da.Fill(ds //ds.Tables[0].TableName = "worker";
  ds.Tables[0].PrimaryKey = new DataColumn[]{ds.Tables[0].Columns["id"]};

  ds.Tables[1].PrimaryKey = new DataColumn[]{ds.Tables[1].Columns["id"]};
  //ForeignKeyConstraint custOrderFK = new ForeignKeyConstraint("CustOrderFK",ds.Tables["worker"].Columns["id"],ds.Tables["worker1"].Columns["bbbid"]);
  //custOrderFK.DeleteRule = Rule.Cascade;
  //ds.Tables["worker1"].Constraints.Add(custOrderFK);

  ds.Tables[1].Rows[0].Delete();//这里只能更新Table[0],不能更新Table[1],请问怎么改?
  da.Update(ds);

------解决方案--------------------
System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter("SELECT * From a11", cn);
System.Data.OleDb.OleDbDataAdapter da1 = new System.Data.OleDb.OleDbDataAdapter("SELECT * From b11", cn);

System.Data.OleDb.OleDbCommandBuilder cb = new System.Data.OleDb.OleDbCommandBuilder(da);
System.Data.OleDb.OleDbCommandBuilder cb1 = new System.Data.OleDb.OleDbCommandBuilder(da1);
da.Fill(ds,"table");
da1.Fill(ds, "table1");
ds.Tables[1].Rows[0].Delete();
da.Update(ds,"table");
da1.Update(ds,"table1");
------解决方案--------------------
探讨
System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter("SELECT * From a11", cn);
System.Data.OleDb.OleDbDataAdapter da1 = new System.Data.OleDb.OleDbDataAdapter("SELECT * From b11", cn);

System.Data.OleDb.OleDbCommandBuilder cb = new System.Data.OleDb.OleDbCommandBuilder(da);
System.Data.OleDb.OleDbCommandBuilder cb1 = new System.Data.OleDb…