Why am I getting this error in my SQL string?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Dransfield
    New Member
    • Jan 2011
    • 46

    Why am I getting this error in my SQL string?

    I get the error that there is "no value given for one or more required parameters" when I attempt to execute this command:

    Code:
    string commandString = "SELECT moduletitle, unit FROM [EXAMDAT] WHERE moduletitle ='" + modules.SelectedItem.ToString() + "';";
    The string looks correct to me, why isn't it working?
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    I suspect that the field names you have listed as

    [moduletitle, unit]

    should be

    [moduletitle], [unit]

    or more simply

    moduletitle, unit

    -Stewart

    Comment

    • Alex Dransfield
      New Member
      • Jan 2011
      • 46

      #3
      Ah sorry, I changed that. I'm still getting the error though and I'm not sure why.

      Here's my full method

      Code:
      private bool checkSame(string mod, string unit)
              {
                  string commandString = "SELECT moduletitle, unit FROM EXAMDAT WHERE moduletitle ='" + modules.SelectedItem.ToString() + "';";
                  try
                  {
                      OleDbCommand command = new OleDbCommand(commandString, connection);
                      OleDbDataReader reader = command.ExecuteReader();
                      while (reader.Read())
                      {
                          if ((reader["moduletitle"] == modules.SelectedItem.ToString()) && (reader["unit"] == units.SelectedItem.ToString()))
                          {
                              return true;
                          }
                          else
                              return false;
                      }
                  }
                  catch (Exception e)
                  {
                      string exception = "Error in retreiving the data" + e;
                      MessageBox.Show(exception);
                      return false;
                  }
      
                  return false;
              }

      Comment

      • johny10151981
        Top Contributor
        • Jan 2010
        • 1059

        #4
        print the query,
        then copy the query
        and then run from your database editing window
        which ever software you are using... and see what went wrong

        few more things where is your mysql server? if it is in linux server make sure table name you typed it exists. Cause in linux its case sensitive

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Which statement is throwing the error?
          What kind of database are you connecting to with the Ole namespace?

          It is possible maybe that the [] are being interpreted not as literals but as markers for a parameter and it is complaining that you have not filled in the parameter? [ ] aren't needed around tablenames/columnnames that do not have spaces in them

          Comment

          Working...