locked
Why do I get an error in this code? RRS feed

  • Question

  • Hi,

    I have a piece of code which has been stable and unchaged for several months working happily.  I had to add a new field to a table and ever since I get an error whenever I run this code with the new SELECT statement.  Old SQL statements work fine.  The connection is good, if I run the new SQL directly on the table it works, no errors.  The error only occurs when running the new code in this code segment.

    I have changed all the SQL statements as well as the table that is related to this table.  The following simple SQL fails "SELECT T_ID, TripName FROM Trip WHERE (V_ID = 1)"  The fields added was TripName.

    Anyone got any ideas or suggestions as to why this fails with the new fields?

    ERROR: "No value given for one or more required parameters"

    The error occurs when the following line is run...

    dAdapter.Fill(dTable);

          try
          {
            //create an OleDbDataAdapter to execute the query
            OleDbDataAdapter dAdapter = new OleDbDataAdapter(pSQLText, CreateConnection());
            //create a command builder
            OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
            //create a DataTable to hold the query results
            DataTable dTable = new DataTable();
            //fill the DataTable
            dAdapter.Fill(dTable);
    
            // add a Log entry
            ErrorLogClass eLC = new ErrorLogClass();
            eLC.LogCode = 0;
            eLC.LogModule = "Query Data Get";
            eLC.LogMessage = "Success Records returned. ( " + dTable.Rows.Count.ToString() + ")";
            eLC.LogMessageToFile();
            // complete the execution of the query and collect records
            return dTable;
          }
          catch (OleDbException oDBE)
          {
            ErrorLogClass eLC = new ErrorLogClass();
            eLC.LogCode = 8;
            eLC.LogModule = "Query Data Get";
            eLC.LogMessage = "An error occured. (" + oDBE + ")";
            eLC.LogMessageToFile();
            // complete the execution of the query and collect records
            return new DataTable();
          }
          finally
          {
            dbConn.Close();
          }
    

    SquireDude
    Tuesday, August 10, 2010 8:56 PM

Answers

  • Okay,

    I've found the problem... It was not copying the DB over to the working directory... hence the DB I was looking at had the new fields etc BUT the running copy did not. 

    FIX: Select the DB
    Open the Properties
    Select "Copy to Output Directory" and change the value to either "Copy if Newer" or "Copy Always"

    Thanks


    SquireDude
    • Marked as answer by SquireDude Tuesday, August 10, 2010 11:02 PM
    Tuesday, August 10, 2010 11:02 PM

All replies

  • Does select * have the same problem? Also what did the old SQL statement look like?

    Why is there a V_ID and  T_ID? Is it a mistake in typing?


    William Wegerson (www.OmegaCoder.Com)
    Tuesday, August 10, 2010 9:13 PM
  • Good questions OmegaMan...

    First:- I have not tried "SELECT *..." so I will have to get back to you on that point.

    Second:- The old SQL was "SELECT T_ID, TripName, TStart + ' (' & TSDate & ') -> ' + TDestination + ' (' & TADate & ')' AS Trip, TStartWPID FROM Trip WHERE (V_ID = " + pID + ") ORDER BY TSDate";

    Third:- T_ID is the Trip ID value while V_ID is the Vessel ID value.


    SquireDude
    Tuesday, August 10, 2010 10:47 PM
  • Okay,

    I've found the problem... It was not copying the DB over to the working directory... hence the DB I was looking at had the new fields etc BUT the running copy did not. 

    FIX: Select the DB
    Open the Properties
    Select "Copy to Output Directory" and change the value to either "Copy if Newer" or "Copy Always"

    Thanks


    SquireDude
    • Marked as answer by SquireDude Tuesday, August 10, 2010 11:02 PM
    Tuesday, August 10, 2010 11:02 PM