c#把代码写入数据库为什么错误
privatevoidbutton1_Click(objectsender,EventArgse){if(textBox2.Text==""&&textBox3.Text...
private void button1_Click(object sender, EventArgs e)
{
if (textBox2.Text == "" && textBox3.Text == "")
label2.Text = "请输入密码";
else if (textBox2.Text == textBox3.Text)
{
string b = textBox2.Text;
string c = textBox1.Text;
OleDbCommand cmd = new OleDbCommand(@"insert into list(user,pwd) values('" + c + "','" + b + "')", con);
con.Open();
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
Form1 f3 = new Form1();
f3.Show();
this.Hide();
}
}
大家快帮帮忙为什么错了 展开
{
if (textBox2.Text == "" && textBox3.Text == "")
label2.Text = "请输入密码";
else if (textBox2.Text == textBox3.Text)
{
string b = textBox2.Text;
string c = textBox1.Text;
OleDbCommand cmd = new OleDbCommand(@"insert into list(user,pwd) values('" + c + "','" + b + "')", con);
con.Open();
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
Form1 f3 = new Form1();
f3.Show();
this.Hide();
}
}
大家快帮帮忙为什么错了 展开
1个回答
展开全部
拼接字符串,容易出错。
改成这样:
string s = String.Format("insert into list(user,pwd) values ('{0}','{1}')",b,c);
改成这样:
string s = String.Format("insert into list(user,pwd) values ('{0}','{1}')",b,c);
更多追问追答
追问
这是改哪里啊
追答
string s = String.Format("insert into list(user,pwd) values ('{0}','{1}')",b,c);
OleDbCommand cmd = new OleDbCommand( s, con);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询