日期:2014-05-19  浏览次数:21219 次

郁闷,请教各位关于
借别人程序一用

static   void   Main(string[]   args)
{
string   s= "initial   catalog=fucai;data   source=.;integrated   security=true ";
SqlConnection   thisConnection   =new   SqlConnection(s);
thisConnection.Open();
SqlDataAdapter   thisDataAdapter   =new   SqlDataAdapter( "select   RTIM(id)   id,RTIM(name)   name   from   member ",thisConnection);
SqlCommandBuilder   thisCommandBuilder   =new   SqlCommandBuilder(thisDataAdapter);
DataSet   thisDataSet   =new   DataSet();
thisDataAdapter.Fill(thisDataSet, "member ");
thisDataSet.Tables[ "member "].Rows[0][ "name "]= "王鹏11 ";
thisDataAdapter.Update(thisDataSet, "member ");(在这一步出现错误说无法生成动态SQL语句)
thisConnection.Close();
}

其中id我已设为主键,执行后出现以上错误
当我把RTIM(id)去掉RTIM后,如select   id,rtim(name)   from   member;
同时修改name的值,然后update,没出现错误,但name也没有被修改
当我把RTIM(name)去掉RTIM后,如select   id,name   from   member;再update,
就能把name修改了

请问为何会出现上面的原因呢?

------解决方案--------------------
请设置一条修改语句给thisAdapter.UpdateCommand
------解决方案--------------------
在數據庫中,你把該表的name的類型由char改為varchar,就行了,也不用rtrim了