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 属性尚未初始化。“ 怎么解决????
SqlCommand cmd = new SqlCommand();
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();
SqlCommand cmd = new SqlCommand(conn, sql);
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() 了。
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捕获错误信息
疯了!!!!!
SqlCommand cmd = new SqlCommand();你看一下构造函数,可以带什么参数
这样吧,你先去百度找下ado.net的资料看一下,学一下比较好,你这样问题太多了,都是基础。
SqlCommand的两个参数的构造函数:第一个参数是CommmandText,第二个参数是sqlConnection
改成
SqlCommand cmd = new SqlCommand(sql,conn);请自己多看看这几个数据库操作对象
conn.Open();
string sql = ""; // sql语句
SqlCommand cmd = new SqlCommand(sql, conn);
int i = Convert.ToInt32(cmd.ExecuteNonQuery());
if (i > 0)
{
}
else
{
}