如题,代码如下:
string mySelectQuery,strsql,syclient, uid,pwd;
mySelectQuery= "Select * from sap_wt_temp ";//select语句
syclient = xmlread( "sybasesvr ");//服务器
uid = xmlread( "sybaseuid ");//用户名
pwd = xmlread( "sybasepwd ");//密码
strsql = "Driver={Sybase System 11};SRVR= "+syclient+ ";DB=shxsdb;UID= "+uid+ ";PWD= "+pwd+ ";CharSet=cp850;appname=sap_wt_test "; //驱动
OdbcConnection myConn= new OdbcConnection(strsql);
OdbcDataAdapter myDataAdapter = new OdbcDataAdapter();
myDataAdapter.SelectCommand = new OdbcCommand(mySelectQuery, myConn);
OdbcCommandBuilder custCB = new OdbcCommandBuilder(myDataAdapter);
myDataAdapter.InsertCommand = custCB .GetInsertCommand();
myDataAdapter.UpdateCommand = custCB .GetUpdateCommand();
myDataAdapter.DeleteCommand = custCB.GetDeleteCommand();
myConn.Open();
myDataAdapter.Update(ds, "temp ");
myConn.Close();
有一点需要说明的就是,ds是从另一个数据库查出来的dataset,但是它里面的表(名字是temp)里的字段和表sap_wt_temp(update前表是空的)都是一样的,但是为什么update后只有主键被更新???
sap_wt_temp里的字段,我都设成允许null,不然会提示错误,要插入的字段不能为null。
谢谢各位大虾!!
------解决方案--------------------------------------------------------
算了,我用insert完成了,自己接分了