MySqlConnection conn=new MySqlConnection("连接字符串");
conn.Open();
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select * from user where username ='asdasd'";
MySqlDataAdapter da =new MySqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds =new DataSet();
da.Fill(ds);
ds.Tables[0].Rows[0][4] ="asdasdasd";//一共有12列,类型也都正确
MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
da.UpdateCommand = cb.GetUpdateCommand();
da.Update(ds);
conn.Close();调了很久,还是没弄明白,为什么就是改不了数据库呢
请各位指点一下

解决方案 »

  1.   

    da.UpdateCommand.CommandText = "UpDate ...";
      

  2.   

    da.UpdateCommand = cb.GetUpdateCommand();
    这句不是可以自动生成命令吗,我输出了一下,是Update 表名 where(('ID=@p1'))
    真是SQL语句错了吗
      

  3.   

    为什么不直接写语句 更新呢  update user set username='asdasdasd' where username='asdasd'
      

  4.   

    试试各种方法呗,直接写SQL语句都写了N久了换一下
      

  5.   

    给ds.Tables[0]这个表设置主键如下:
    ds.Tables[0].Rows[0][4] ="asdasdasd";//一共有12列,类型也都正确
    //新加代码
    ds.Tables[0].PrimaryKey= new DataColumn{ds.Tables[0]["Id"]};如果我没有记错的话,好像是这样的
      

  6.   

    update tablename set a=b,c=d......
    [from tablename]
    where xxx....
    好象这么会事情,
    是不是没主键
      

  7.   

    主键设置了吗
    commandbuilder是要主键的
    cb.GetUpdateCommand();
    这句是多余的
    cb自动生成,不必写
      

  8.   

    这样写好像有点错误
    我改了一下不报错了,也不知道对不对
    ds.Tables[0].PrimaryKey = new DataColumn[]{ds.Tables[0].Columns[0]};
    可是也不好使啊
      

  9.   

    cmd.CommandText = "select * from user where username ='asdasd'";
    为什么不直接用update修改