string appName=ConfigurationSettings.AppSettings["myConn"]; 
   SqlConnection sqlConn=new SqlConnection(appName); 
   string sqlSelect="select * from BaseProjectInfo where ProjectID='"+strPid+"'"; 
   SqlDataAdapter sqlAdpter=new SqlDataAdapter(sqlSelect,sqlConn); 
   SqlCommandBuilder cb = new SqlCommandBuilder(sqlAdpter);
   DataSet myDs=new DataSet(); 
   try 
   { 
    sqlAdpter.Fill(myDs,"BaseProjectInfo"); 
    if(myDs.Tables["BaseProjectInfo"].Rows.Count==1) 
    { 
        DataRow myDr=myDs.Tables["BaseProjectInfo"].Rows[0]; 
        myDr["name"]=strName; //strName是参数
        myDr["password"]=strPassword; //strPassword是参数
        sqlAdpter.Update(myDs,"BaseProjectInfo"); 
        myDs.AcceptChanges(); 
this is bad, you can just run 
update yourtable set name='newname' and password='newpassword' ....

解决方案 »

  1.   

    你对myDr的操作和对myDS的操作好像没什么关联呀,当然不会加进来了
      

  2.   

    to saucer:直接用set的话就会另加一行吧?我要加到同一行上。
      

  3.   

    为什么不用update语句呢?对数据表的副本操作的方法不太好
      

  4.   

    表中是这样的
    id   name grade
    1    null  null
    我要的结果是
    id   name    grade
    1    xxx      xxx
      

  5.   

    我用了datarow.acceptchanges,出错了。
    自己瞎改的:)
      

  6.   

    myCmd.Connection.Open();
    myCmd.CommandText="insert into BaseProjectInfo(); valuemyCmd.ExecuteNonQuery();
    sqlConn.Close();
    这样加的不在原来的行上
      

  7.   

    you probably need to use SqlParameters, but you can try the following for nowSqlCommand cmd = new SqlCommand("select * from BaseProjectInfo; if @@rowcount = 1 update BaseProjectInfo set name='" + strName + "', password='" + strPassword + "'", sqlConn);
    sqlConn.Open();
    cmd.ExecuteNonQuery();
    sqlConn.Close();