Sql = "连接数据库";
        SqlConnection cn = new SqlConnection(sql);
        cn.Open();
        string str = "insert into 表名(字段名...逗号隔开) values('" + TextBox1.Text + "','" + TextBox2.Text + "')";
        SqlCommand cmd = new SqlCommand(str, cn);
        cmd.ExecuteNonQuery();
        cn.Close();

解决方案 »

  1.   

            Sql = "连接数据库";
            SqlConnection cn = new SqlConnection(sql);
            cn.Open();
            string str = "insert into 表名(字段1,字段2,字段3...) values('" + TextBox1.Text + "','" + TextBox2.Text + "')";
            SqlCommand cmd = new SqlCommand(str, cn);
            cmd.ExecuteNonQuery();
            cn.Close();
      

  2.   

            Sql = "连接数据库";
            SqlConnection cn = new SqlConnection(sql);
            cn.Open();
            string str = "insert into 表名(字段1,字段2,字段3,...) values('" + TextBox1.Text + "','" + TextBox2.Text + "','你要添加的数据值',...)";
            SqlCommand cmd = new SqlCommand(str, cn);
            cmd.ExecuteNonQuery();
            cn.Close(); 
      

  3.   

    str=" insert into 表名(字符型字段,数值型字段,日期型字段) values('"& 字符型变量 &"',"& 数值型变量 &",'"& 日期型变量 &"')"