没有给出一个或多个必需参数的值。()

时间:2012-04-13 10:55:43

标签: c# ms-access

我遇到了问题,当我登录时发生错误,没有给出一个或多个必需参数的值。

protected void imgbtn_login_Click(object sender, ImageClickEventArgs e)
{
    int UserId = 0;
    string str = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=pathto.mdb;Persist Security Info=False;");
    OleDbConnection conn = new OleDbConnection(str);
    conn.Open();
    string query = "select * from Users where LoginName='" + txt_logname.Text + "' and Password='" + txt_pass.Text + "';";
    OleDbDataAdapter da=new OleDbDataAdapter(query,conn);
    DataSet ds = new DataSet();

    da.Fill(ds);
    DataTable dt = new DataTable();

    dt = ds.Tables[0];
    try
    {
        UserId = Int32.Parse(dt.Rows[0]["UserId"].ToString());

        //btn_LogIn.Text = "Login Succeded";
        Response.Redirect("Register.aspx");
    }
    catch (Exception ex)
    {

    }
    txt_logname.Text = " ";
    txt_pass.Text = "";
}

1 个答案:

答案 0 :(得分:3)

密码是保留字。把它放在方括号[密码]

请参阅Syntax error in INSERT INTO statement