你要是新建一条记录,应该用insert into 而不是update

解决方案 »

  1.   

    SqlConnection myConnection = new SqlConnection("server=.;user id=sa;password=;database=CSTest");
    SqlCommand myCommand=new SqlCommand("INSERT INTO Info(name,phone,mobilephone,company) VALUES('"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"','"+TextBox4.Text+"')",myconnection );
    myCommand.Connection.Open();
    myCommand.ExecuteNonQuery();
    myCommand.Connection.Close();
      

  2.   

    string selcmd = "INSERT INTO Info(name,phone,mobilephone,company) VALUES('"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"','"+TextBox4.Text+"'",
    SqlCommand mySqlCommand = new SqlCommand(selcmd,Conn);
    try
    {
    cn.Open();
    mySqlCommand.ExecuteNonQuery();

    }
    catch(SqlException ex)
    {
    throw new Exception("打开数据库出错"+ex.Message);
    }
    finally
    {
    cn.Close();
    }
      

  3.   

    为什么要用Dataset?
    直接Command.ExclNonQuery之类的就可以了