例如:表123里面数据是:(文本框是2个,一个用于输入数据,一个用于显示数据)
  序号 ID name age
  010 1234 tom 45
  011 1236 ken 23
  012 1269 bom 60  
当输入056点击"更新"按钮时,文本框显示更新的数据.
数据库是SQL Server 2005 ,开发平台是Visual Studio 2010.
  

解决方案 »

  1.   

    就写UPDATE 的 SQL 执行,重新绑定,不就行了嘛
      

  2.   

    我学的不好,我需要VisualC#中如何更新数据表的数据的具体代码
      

  3.   


    update 表名 set name《你想要更新的列》= 更新的值 where id = 056
      

  4.   

    也许我没有说明白,我需要Visual C#点击“更新”按钮,文本框显示更新的数据的整段代码。
      

  5.   

      using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    try
                    {
                        string selectsql ="update tUSER set userID= textBox_name where id = 056";
                        SqlCommand cmd = new SqlCommand(selectsql, connection); //conn就是创建的SqlConnection实例                    string info = String.Empty; //表结果 
                        SqlDataReader odr = cmd.ExecuteReader();
                        while (odr.Read())
                        {
                            string tempinfo = odr[0].ToString() + " " + odr[1].ToString() + " " + odr[2].ToString() + " " + odr[3].ToString() + "\n";                        info += tempinfo;//显示表格全部记录                    }                    textBox_output.Text = info; //将info显示到文本框中,info为文本框的名称,
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    connection.Close();
                }
    我执行这段代码,当我运行时,点击更新,文本框未显任何数据,麻烦各位帮我看一下,这段代码有什么问题.
      

  6.   

    try
    {
     strsqlUpdate="update tUSER set name = @p1 where id = 056";//这一句更新的时候错了,对应错字段了
     SqlCommand sqlCmd = new SqlCommand(strsqlUpdate,Conn);
     //加入参数
     SqlCmd.Parameters.Add("P1",SqlDbType.NVarchar);
    //参数赋值
     SqlCmd.Parameters["@P1"].Value=textBox_name.Text.Trim();
     int iResult=sqlCmd.ExecuteNonquery();
     if(iResult>)
      {
      MessageBox.Show("更新成功!","提示");
       }
    catch
    {
      MessageBox.Show("更新操作失败","失败");}
    后面写getInfo()的方法
      

  7.   

    ExecuteNonquery();和SqlDbType.NVarchar需要什么引用,因为我执行了你的代码,上述两个有问题
      

  8.   

    拼写错误:            try
    {
     strsqlUpdate="update tUSER set name = @p1 where id = 056";//这一句更新的时候错了,对应错字段了
     SqlCommand sqlCmd = new SqlCommand(strsqlUpdate,Conn);
     //加入参数
     sqlCmd.Parameters.Add("P1",SqlDbType.NVarChar);
    //参数赋值
     sqlCmd.Parameters["@P1"].Value=textBox_name.Text.Trim();
     int iResult=sqlCmd.ExecuteNonQuery();
     if(iResult>)
      {
      MessageBox.Show("更新成功!","提示");
       }
    catch
    {
      MessageBox.Show("更新操作失败","失败");}