C#写的一段小代码,可调试的时候总是出现问题,郁闷的是我几乎是从书上抄下来的代码,请大家帮忙看看,是拿了错了,谢谢了
string name = Login1.UserName; string password = Login1.Password; string connection = @"provider=microsoft.ace.oledb.12.0; Data Source=g:\临时\数据库事例\用户信息.accdb"; OleDbConnection conn = new OleDbConnection(connection); OleDbCommand command = new OleDbCommand(string.Format ("Select count(*) From user Where name='{0}' and password='{1}'", name, password)); conn.Open(); int count = (int)command.ExecuteScalar(); if (count > 0) { e.Authenticated = true; Response.Redirect("http://www.t.sina.com.cn/"); } else { e.Authenticated = false; ClientScript .RegisterStartupScript (this.GetType (),"无此用户","<script language='javascript'>alert('你输入的信息有误')</script>"; } conn.Close();
7 回答
慕森卡
TA贡献1806条经验 获得超8个赞
稍微那么一看,感觉你的OleDbCommand那句有问题
OleDbCommand command = new OleDbCommand(string.Format ("Select count(*) From user Where name='{0}' and password='{1}'", name, password));
没见你把command跟connection关联起来。。。。下面这样就对了
OleDbCommand command = new OleDbCommand(string.Format ("Select count(*) From user Where name='{0}' and password='{1}'", name, password), connection);
- 7 回答
- 0 关注
- 323 浏览
添加回答
举报
0/150
提交
取消