大家好啊
string inser="insert into xuesheng (name,password) values ('"+this.textBox1 .Text +"','"+this.textBox2 .Text +"')";
          System.Data .SqlClient.SqlCommand da=new SqlCommand (inser,sqlConnection1);
da.ExecuteNonQuery ();
                                 MessageBox.Show ("添加成功");在sql server 中我这样添加数据为什么不行的啊,请大家帮我修改一下吧,是真的比较急. 它报ExecuteNonQuery当前状态为关闭.

解决方案 »

  1.   

    必须显示打开连接.
    在da.ExecuteNonQuery ();前加入da.Connection.Open();string inser="insert into xuesheng (name,password) values ('"+this.textBox1 .Text +"','"+this.textBox2 .Text +"')";
    System.Data .SqlClient.SqlCommand da=new SqlCommand (inser,sqlConnection1);
    da.Connection.Open();
    da.ExecuteNonQuery ();
    MessageBox.Show ("添加成功");
      

  2.   

    错误提示不是很明白吗?你看看你的OPEN了么?
      

  3.   

    。。错误说的不是很明白了没,你没带开连接啊,openO,最后绑定后记得关闭close();