C#寫的一段小代碼,可調(diào)試的時候總是出現(xiàn)問題,郁悶的是我?guī)缀跏菑臅铣聛淼拇a,請大家?guī)兔纯矗悄昧隋e了,謝謝了
string name = Login1.UserName; string password = Login1.Password; string connection = @"provider=microsoft.ace.oledb.12.0; Data Source=g:\臨時\數(shù)據(jù)庫事例\用戶信息.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條經(jīng)驗 獲得超8個贊
稍微那么一看,感覺你的OleDbCommand那句有問題
OleDbCommand command = new OleDbCommand(string.Format ("Select count(*) From user Where name='{0}' and password='{1}'", name, password));
沒見你把command跟connection關聯(lián)起來。。。。下面這樣就對了
OleDbCommand command = new OleDbCommand(string.Format ("Select count(*) From user Where name='{0}' and password='{1}'", name, password), connection);
- 7 回答
- 0 關注
- 363 瀏覽
添加回答
舉報
0/150
提交
取消