locked
accdb error RRS feed

  • Question

  • User54078450 posted

    Hi guys . I have a form with the following code in it's on_load.


    public partial class ResetPassword : System.Web.UI.Page
    {
        string RetrievedValue;
        protected void Page_Load(object sender, EventArgs e)
        {
            this.LblUserID.Text = Request.QueryString["UserID"];
            RetrievedValue = this.LblUserID.Text;

            string connString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data source =" + (Request.PhysicalApplicationPath + "App_Data\\Information.accdb");
                                                                   
            OleDbConnection conn = new OleDbConnection(connString);
            conn.Open();

            OleDbCommand cmd = conn.CreateCommand();

            cmd.CommandText = "SELECT Question FROM Buyers WHERE UserID = Roelofjvv";
            OleDbDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                  string question = (string)reader["Question"];
             
                   LblQuestion.Text = question;
            }
            conn.Close();
        }


    When i run the code it throws me a error at line --OleDbDataReader reader = cmd.ExecuteReader();--


    The error : No value given for one or more required parameters.

    Any help will be appriciated

    Thanks

    Wednesday, December 8, 2010 5:11 PM

Answers

  • User-1199946673 posted

    When you pass a string, you need to enclose it in quotes, otherwise Access will thread the value (Roelofjvv) as a parameter

     cmd.CommandText = "SELECT Question FROM Buyers WHERE UserID = 'Roelofjvv'";

    But perhaps you should start using parameter queries:

    http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access

    cmd.CommandText = "SELECT Question FROM Buyers WHERE UserID = @userID";
    cmd.Parameters.AddWithValue("userID", "Roelofjvv");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 8, 2010 5:21 PM

All replies

  • User-1199946673 posted

    When you pass a string, you need to enclose it in quotes, otherwise Access will thread the value (Roelofjvv) as a parameter

     cmd.CommandText = "SELECT Question FROM Buyers WHERE UserID = 'Roelofjvv'";

    But perhaps you should start using parameter queries:

    http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access

    cmd.CommandText = "SELECT Question FROM Buyers WHERE UserID = @userID";
    cmd.Parameters.AddWithValue("userID", "Roelofjvv");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 8, 2010 5:21 PM
  • User54078450 posted

    Thanks for the help!

    Wednesday, December 8, 2010 5:26 PM