【问题标题】:No value given for one or more required parameters.()没有为一个或多个必需参数提供值。()
【发布时间】:2012-04-13 19:02:11
【问题描述】:

我有一个问题,当我登录时发生错误,即没有为一个或多个必需参数提供值。

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 = "";
}

【问题讨论】:

  • 空的 catch 块是邪恶的。避开他们。
  • 以您正在执行的方式连接 SQL 对 SQL Injection 开放 - 避免这种情况并使用参数化查询。
  • 请在您的代码中指出错误发生的位置。我认为您发布的代码与它没有任何关系。
  • 即使我们试图在您之前的帖子中为您提供建议,您也会犯同样的错误:stackoverflow.com/questions/10137279/…

标签: c# ms-access


【解决方案1】:

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

Syntax error in INSERT INTO statement

【讨论】:

  • @Marco 我应该使用大写字母吗? :D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多