以下是插入语句,但我还想实现更新当前数据库中的数据,不知道UPDATA语句怎么写,请指教!谢谢string myConnectionString="Data Source=ghost;Initial Catalog=hwinfo;User Id=sa;Password=admin";
SqlConnection myConnection = new SqlConnection(myConnectionString);
string mycn="update infolist set(name,datatime,branch) values('"+this.nametext.Text+"','"+this.timetext.Text+"','"+this.branch.SelectedItem.Value+"')";
SqlCommand myComm = new SqlCommand(mycn);
myComm.Connection = myConnection;
myComm.Connection.Open();
myComm.ExecuteNonQuery();
myConnection.Close();

解决方案 »

  1.   

    string mycn="update infolist set=name '"+this.nametext.Text+"',datatime='"+this.timetext.Text+"',branch='"+this.branch.SelectedItem.Value+"'";
      

  2.   

    string mycn="update infolist set name='"+this.nametext.Text+"',datatime='"+this.timetext.Text+"',branch'"+this.branch.SelectedItem.Value+"' where a='"+a+"'";
    //a是条件
      

  3.   

    string myConnectionString="Data Source=ghost;Initial Catalog=hwinfo;User Id=sa;Password=admin";
    SqlConnection myConnection = new SqlConnection(myConnectionString);
    string mycn="update infolist set name='"+this.nametext.Text+"',datatime='"+this.timetext.Text+"',branch='"+this.branch.SelectedItem.Value+"' where id=.....条件";
    SqlCommand myComm = new SqlCommand(mycn);
    myComm.Connection = myConnection;
    myComm.Connection.Open();
    myComm.ExecuteNonQuery();
    myConnection.Close();
      

  4.   

    string mycn="update infolist set(name,datatime,branch) values('"+this.nametext.Text+"','"+this.timetext.Text+"','"+this.branch.SelectedItem.Value+"')";
    ==》
    string mycn="update infolist set name = '"+this.nametext.Text+"',datatime='"+this.timetext.Text+"',branch = '"+this.branch.SelectedItem.Value+"') where ...";
      

  5.   

    楼主如果每次插入的时候都要做update的操作的话,建议写一个触发器。
      

  6.   

    提示我"myComm.ExecuteNonQuery();"附近有语法错误
    这是怎么回事!?!?
    谢谢
      

  7.   

    string mycn=String.Format("update infolist set name='{0}',datatime='{1}',branch='{2}'",this.nametext.Text,this.timetext.Text,this.branch.SelectedItem.Value);
      

  8.   

    string myConnectionString="Data Source=ghost;Initial Catalog=hwinfo;User Id=sa;Password=admin";SqlConnection myConnection = new SqlConnection(myConnectionString);string mycn=String.Format("update infolist set name='{0}',datatime='{1}',branch='{2}'",this.nametext.Text,this.timetext.Text,this.branch.SelectedItem.Value);
    SqlCommand myComm = new SqlCommand(mycn , myConnection);myConnection.Open();
    myComm.ExecuteNonQuery();
    myConnection.Close();
      

  9.   

    string mycn="update infolist set name='"+this.nametext.Text+"',datatime='"+this.timetext.Text+"',branch='"+this.branch.SelectedItem.Value+"' where id=.....条件";
      

  10.   

    string mycn="update infolist set name='"+this.nametext.Text+"',datatime='"+this.timetext.Text+"',branch'"+this.branch.SelectedItem.Value+"' where a='"+a+"'";
    //a是条件