namespace Database
{
public class Dbase
{
private string ss = "Integrated Security=SSPI;User Id=sa;database=jindu;server=localhost";
public SqlConnection sqlcon;
public static System.DateTime[] time = new System.DateTime[50];
public Dbase()
{
this.sqlcon=new SqlConnection(this.ss);
sqlcon.Open();
}
public DataSet getdataset(string Sqltext)
{
DataSet ds=new DataSet ();
SqlDataAdapter da = new SqlDataAdapter(Sqltext, this.ss);
SqlCommandBuilder thisbuilder = new SqlCommandBuilder(da);
da.Fill(ds);
return ds;
} public void update(string Sqltext,string table)
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(Sqltext, this.ss);
SqlCommandBuilder thisbuilder = new SqlCommandBuilder(da);
da.Fill(ds);
da.Update(ds,table);
}
}
namespace manage
{
public partial class sonproject : Form
{
........................
string cm = "select * from sonproject ";
Dbase db = new Dbase();
DataSet ds = new DataSet();
ds = db.getdataset(cm);
DataRow thisrow = ds.Tables[0].NewRow();
thisrow ["父项目编号"]=pronumtext .Text ;
thisrow ["子项目编号"]=sonpronumtext .Text ;
thisrow ["子项目名称"]=sonpronametext .Text ;
thisrow ["开始时间"]=sonprobegindatetime .Value ;
thisrow["结束时间"] = sonproenddatetime.Value;
thisrow ["前置子项目"]=sonprobeforetext.Text ;
thisrow ["负责人"]=sonprobeforetext .Text ;
thisrow ["负责公司"]=sonprocompanytext .Text ;
string tb = "sonproject";
ds.Tables[0].Rows.Add(thisrow);
db.update(cm,tb); //此处为什么会出现如题所示的错误呢
.................................
}
SqlDataAdapter da = new SqlDataAdapter(Sqltext, this.ss);
SqlCommandBuilder thisbuilder = new SqlCommandBuilder(da);//确保此处sqltext返回了主键信息===================================================================
da.SelectCommand = thisbuilder .GetInsertCommand();
da.UpdateCommand = thisbuilder .GetUpdateCommand();
da.DeleteCommand = thisbuilder .GetDeleteCommand();
===================================================================
da.Fill(ds);
da.Update(ds,table);
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(Sqltext, this.ss);
SqlCommandBuilder thisbuilder = new SqlCommandBuilder(da);
DataColumn[] keys = new DataColumn[1];
keys[0] = ds.Tables[0].Columns[1]; //无法找到表 0。
ds.Tables[table].PrimaryKey = keys;
da.UpdateCommand = thisbuilder.GetUpdateCommand();
da.Fill(ds);
da.Update(ds,table);
}
我把上面update()方法修改如上,却提示找不到表0,那个表不就是sqltext打开的那个表吗,为什么还提示找不到呢
================〉〉 da.Fill(ds,table);
if (!ds.HasChanges())
{
da.Update(ds,table);
ds.AcceptChanges();
}
请问能加你qq吗
158695389我qq