c# 连接access时出现 未处理oledbexception 错误
mycon.Open();stringsql1="selectusernamefromloginwhereusername='"+textBox1.Text.Trim()...
mycon.Open();
string sql1 = "select username from login where username = '" + textBox1.Text.Trim() + "',password='" + textBox2.Text.Trim() + "'";
OleDbCommand cmd = new OleDbCommand("", mycon);
cmd.CommandText = sql1;
if (null == cmd.ExecuteScalar())
{
string sql2 = "insert into login (username,password)" + " values ('" + textBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "')";
cmd.CommandText = sql2;
cmd.ExecuteNonQuery();
MessageBox.Show("添加用户成功!", "提示"); 展开
string sql1 = "select username from login where username = '" + textBox1.Text.Trim() + "',password='" + textBox2.Text.Trim() + "'";
OleDbCommand cmd = new OleDbCommand("", mycon);
cmd.CommandText = sql1;
if (null == cmd.ExecuteScalar())
{
string sql2 = "insert into login (username,password)" + " values ('" + textBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "')";
cmd.CommandText = sql2;
cmd.ExecuteNonQuery();
MessageBox.Show("添加用户成功!", "提示"); 展开
展开全部
OleDbCommand cmd = new OleDbCommand("", mycon)这句改为:
OleDbCommand cmd = new OleDbCommand(sql1, mycon).
sql1语句中的username = '" + textBox1.Text.Trim() + "',password='" + textBox2.Text.Trim() + "'";
改为username = '" + textBox1.Text.Trim() + "' and password='" + textBox2.Text.Trim() + "'";
OleDbCommand cmd = new OleDbCommand(sql1, mycon).
sql1语句中的username = '" + textBox1.Text.Trim() + "',password='" + textBox2.Text.Trim() + "'";
改为username = '" + textBox1.Text.Trim() + "' and password='" + textBox2.Text.Trim() + "'";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
string sql1 = "select username from login where username = '" + textBox1.Text.Trim() + "',password='" + textBox2.Text.Trim() + "'";
password前多了个逗号吧应该是and
password前多了个逗号吧应该是and
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
string sql1 = "select username from login where username = '" + textBox1.Text.Trim() + "' and password='" + textBox2.Text.Trim() + "'";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
估计是OleDbCommand cmd = new OleDbCommand("", mycon)这句出错。
初始化OleDbCommand时给空字符串可能出现异常.
试试改为:
OleDbCommand cmd = new OleDbCommand();
cmd.Connection=mycon;
cmd.CommandText = sql1;
初始化OleDbCommand时给空字符串可能出现异常.
试试改为:
OleDbCommand cmd = new OleDbCommand();
cmd.Connection=mycon;
cmd.CommandText = sql1;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询