我已经设计了一个在C#中的ASP登录页。Net.I正在使用的OleDbCommand检查登录凭据。
以下是代码: -
尝试
当我点击登录按钮时,我得到一个异常即[System.Data.OleDb.OleDbException(0x80040E14)语法错误在查询表达式'用户ID(操作符丢失)=?和Psswrd =?"。在System.Data System.Data.OleDb.OleDbCommand.ExecuteCommandText(对象executeResult)(tagDBPARAMS DBPARAMS,对象executeResult)在System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult小时)。 OleDb.OleDbCommand.ExecuteCommand(的CommandBehavior行为,对象executeResult)(的CommandBehavior行为,String方法)在System.Data.OleDb.OleDbCommand.ExecuteReaderInternal在System.Data.OleDb.OleDbCommand.ExecuteScalar()在ScindiaEvents.Account.Login.Button1_Click的(对象发件人,EventArgs e)在C:\用户\ jahart \ \的Visual Studio 2010 \项目\ ScindiaEvents \ ScindiaEvents \帐户\ Login.aspx.cs:第47行] {
string connect = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=C:/Users/jahart/Documents/Visual Studio 2010/Projects/ScindiaEvents/ScindiaEvents/Account/Events.mdb;";
string query = "Select Count(*) From Students Where User ID = ? And Psswrd = ?";
int result = 0;
using (OleDbConnection conn = new OleDbConnection(connect))
{
using (OleDbCommand cmd = new OleDbCommand(query, conn))
{
cmd.Parameters.AddWithValue("User ID", "TextBox1.Text");
cmd.Parameters.AddWithValue("Psswrd", "TextBox2.Text");
conn.Open();
Session["User"] = TextBox1.Text;
result = (int)cmd.ExecuteScalar();
}
}
if (result > 0)
{
Response.Redirect("Default.aspx");
}
else
{
lblMessage.Text = "Invalid credentials";
}
}
catch (Exception ex)
{
lblMessage.Text = ex.ToString();
}
}
可有人请帮助我这部分。
thanx在账款。