没做过数据库的,比较菜,有个题目求教一下,
本机已经建好一个数据库 库名test  表名m_user, 内容包括name password age,内容显示在窗体上,以三个text分别显示 ,现在已经可以读取数据库内容 ,请问如何更新呢,点button按钮将text里修改过的内容传入数据库,比较菜啊 ,大家别骂我啊
        
           //提取文本框中内容
            string temp_age = this.ageTextBox.Text;
            string temp_pwd = this.passwordTextBox.Text;
            string temp_name = this.nameTextBox.Text;            DataSet thisDataSet = new DataSet();
           
            //构建一个主键
            //DataColumn[] keys = new DataColumn[1];
            //keys[0] = thisDataSet.Tables["m_user"].Columns["name"];
            //thisDataSet.Tables["m_user"].PrimaryKey = keys;
            thisAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
            //找到一个匹配行
            thisAdapter.Fill(thisDataSet,"m_user");
            DataRow findRow = thisDataSet.Tables["m_user"].Rows.Find(temp_name);            //对该行的值进行改变
            thisDataSet.Tables["m_user"].Rows[1]["password"] = temp_pwd;
            thisDataSet.Tables["m_user"].Rows[1]["age"] = temp_age;            //数据库更新
           thisAdapter.Update(thisDataSet, "m_user");          最好能给出代码 ,另外再问一下给分怎么给的 

解决方案 »

  1.   

    数据库更新中加一句
    thisAdapter.Fill(thisDataSet,"m_user");
    試試
      

  2.   

    参看
    http://blog.csdn.net/knight94/archive/2006/04/15/664530.aspx需要为DataAdapter初始化其他Command。
      

  3.   

    ,更新数据库,测试通过.vs2005+sql2000private void updateDB()
            {
                try
                {
                    SqlConnection conn = new SqlConnection(PubVar.PubStr);
                    
                    SqlDataAdapter sda = new SqlDataAdapter();
                    sda.SelectCommand = new SqlCommand("delete * form sms_sendout_info",cn); //注意这一句,更新数据库要初始花它的InsertCommand等4个Command
                    cn.Open();
                    DataSet ds = new DataSet();
                    ds.Tables.Add("sms_sendout_info");
                    sda.Fill(ds);
                    sda.Update(ds,"sms_sendout_info");
                }
                catch (Exception err)
                {
                    throw new ApplicationException(err.Message);            }        }
      

  4.   

    我改用下面这个 
    //从数据库中修改指定记录 
                SqlConnection thisConnection = new SqlConnection();            string strUpdt = " UPDATE m_user SET  password = '"
                + passwordTextBox.Text + "' , age = "
                + ageTextBox.Text + " WHERE name = " + nameTextBox.Text;           
                SqlCommand myCommand = new SqlCommand (strUpdt, thisConnection);
                myCommand.ExecuteNonQuery(); 
    还是报错 ExecuteNonQuery requires an open and available Connection. The connection's current state is closed. 何故了,跟踪了一下好象出现在最后一句上
      

  5.   

    在 myCommand.ExecuteNonQuery(); 前
    差一句
    thisConnection.Open();
      

  6.   

    现在做删除,没有报错 ,可是删不掉,更新添加都是正常了
                             
                thisConnection.Open();
                string strDele = "DELETE FROM m_user WHERE name = ' "            +nameTextBox.Text.Trim() + " ' ";
                SqlCommand myCommand = new SqlCommand(strDele, thisConnection);
                myCommand.ExecuteNonQuery();
      

  7.   

    使用update 脚本更新数据库,或者指定updatecommandtext语句