private void button5_Click(object sender, EventArgs e)
        {
            string b1 = textBox1.Text.ToString();
            string b3 = textBox2.Text.ToString();
            string b2 = textBox3.Text.ToString();
            string b4 = textBox4.Text.ToString();
            string b5 = textBox5.Text.ToString();
            SqlConnection conn = new SqlConnection();
            SqlCommand cmd = new SqlCommand();
            conn = new SqlConnection("Data Source=.;Initial Catalog=基于责任中心的企业成本控制系统;Integrated Security=True");
            conn.Open();
            string sql = "delete from 用户信息表 where 用户编码='" + b1 + "',部门编号='" + b2 + "',用户名='" + b3 + "',密码='" + b4 + "',职务='" + b5 + "'";
            int result = cmd.ExecuteNonQuery();
            conn.Close();            if (result > 0)
            {
                MessageBox.Show("删除成功");
            }
            else
            {
                MessageBox.Show("删除失败,请稍候再试");
            }
提示“ExecuteNonQuery: Connection 属性尚未初始化。“  怎么解决????

解决方案 »

  1.   

    SqlConnection conn = null;
    SqlCommand cmd = new SqlCommand();
    conn = new SqlConnection("Data Source=.;Initial Catalog=基于责任中心的企业成本控制系统;Integrated Security=True");
      

  2.   

    还是不行 提示一样的问题 :ExecuteNonQuery: Connection 属性尚未初始化
      

  3.   

    SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=基于责任中心的企业成本控制系统;Integrated Security=True");
    string sql = "delete from 用户信息表 where 用户编码='" + b1 + "',部门编号='" + b2 + "',用户名='" + b3 + "',密码='" + b4 + "',职务='" + b5 + "'";
    SqlCommand cmd = new SqlCommand(cmd,sql);
    cmd.ExecuteNonQuery();
      

  4.   

    // 错了
    SqlCommand cmd = new SqlCommand(conn, sql);
      

  5.   

    提示 局部变量sql 在声明之前无法使用???
      

  6.   

    你的顺序错了,连接串到前边啊 SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=基于责任中心的企业成本控制系统;Integrated Security=True");
      conn.Open();
      string sql = "delete from 用户信息表 where 用户编码='" + b1 + "',部门编号='" + b2 + "',用户名='" + b3 + "',密码='" + b4 + "',职务='" + b5 + "'";
    SqlCommand cmd = new SqlCommand(con,sql);
      int result = cmd.ExecuteNonQuery();
      conn.Close();  if (result > 0)
      {
      MessageBox.Show("删除成功");
      }
      else
      {
      MessageBox.Show("删除失败,请稍候再试");
      }还有textbox 本来就是string 类型的,没必要在 Tostring() 了。
      

  7.   


    private void button5_Click(object sender, EventArgs e)
      {
      string b1 = textBox1.Text.ToString();
      string b3 = textBox2.Text.ToString();
      string b2 = textBox3.Text.ToString();
      string b4 = textBox4.Text.ToString();
      string b5 = textBox5.Text.ToString();
      SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=基于责任中心的企业成本控制系统;Integrated Security=True");
      conn.Open();
      string sql = "delete from 用户信息表 where 用户编码='" + b1 + "',部门编号='" + b2 + "',用户名='" + b3 + "',密码='" + b4 + "',职务='" + b5 + "'";
      SqlCommand cmd = new SqlCommand(conn, sql);
      int result = cmd.ExecuteNonQuery();
      conn.Close();  if (result > 0)
      {
      MessageBox.Show("删除成功");
      }
      else
      {
      MessageBox.Show("删除失败,请稍候再试");
      }
    还有问题,你自己调试一下,try catch捕获错误信息
      

  8.   

    int result = Convert.ToInt32(cmd.ExecuteNonQuery());这个是object类型,需要转换一下
      

  9.   

    你的Sql语句能成功吗,怪了啊!delete from table where id='' and name=''
    疯了!!!!!
      

  10.   


    SqlCommand cmd = new SqlCommand();你看一下构造函数,可以带什么参数
    这样吧,你先去百度找下ado.net的资料看一下,学一下比较好,你这样问题太多了,都是基础。
      

  11.   

    SqlCommand cmd = new SqlCommand(conn, sql);写错了
    SqlCommand的两个参数的构造函数:第一个参数是CommmandText,第二个参数是sqlConnection
    改成
    SqlCommand cmd = new SqlCommand(sql,conn);请自己多看看这几个数据库操作对象
      

  12.   

                SqlConnection conn = new SqlConnection("");//连接字符串
                conn.Open();
                string sql = ""; // sql语句
                SqlCommand cmd = new SqlCommand(sql, conn);
                int i = Convert.ToInt32(cmd.ExecuteNonQuery());
                if (i > 0)
                { 
                    
                }
                else
                { 
                    
                }