DbCommandBuilder的问题,请教!!
我用一个DbDataAdapter da=DataBase.GetAdapter("select * from voucher_TB");
//这是另一个类里定义的方法,只指定adapter的select命令文本
DbCommandBuilder cbd = factory.CreateCommandBuilder();
//这句用创建DbCommandBuilder,只是没有指定具体数据库类型
cbd.DataAdapter = da;
//这句把刚才得到的cbd用于da
然后发现在用da进行update时出错,然后在VS里逐步观察,发现根本没有自动生成update的语句。
想请教:
在什么样的情况下,DbCommandBuilder才能自动工作?
抽象的DbCommandBuilder(即没有指定数据库类型,如SqlCommandBuilder)是否就不能自动生成?或其他因素?
望不吝赐教! --------------------编程问答-------------------- 难道我没表述清楚? --------------------编程问答--------------------
--------------------编程问答-------------------- 修正:
DbDataAdapter da = new DbDataAdapter();
da.SelectCommand = new DbCommand(select * from voucher_TB);//需设置其DbConnection...
DbCommandBuilder cb = new DbCommandBuilder(da);
--------------------编程问答-------------------- DbDataAdapter da = new SqlDataAdapter();
DbDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(select * from voucher_TB);//需设置其SqlConnection...
DbCommandBuilder cb = new SqlCommandBuilder(da);
da.SelectCommand = new SqlCommand(select * from voucher_TB);//需设置其SqlConnection...
DbCommandBuilder cb = new SqlCommandBuilder(da);
// 不会自动获取增删改命令,需要手动获取
da.InserCommand = cb.GetInsertCommand();
da.UpdateCommand = cb.GetUpdateCommand();
da.DeleteCommand = cb.GetDeleteCommand();
补充:.NET技术 , C#