Column 'Checklist date' does not belong to table Table.

Locked Column 'Checklist date' does not belong to table Table.

  • Tuesday, February 21, 2012 6:37 PM
     
      Has Code

    Dear Forum,

    Im stuck with this problem when, where I try to add a new data row to my sql Microsoft Access Database, it cannot find it again in C#.
    It must be someting completly obveous what Im missing. it trows a " Column 'Checklist date' does not belong to table Table. " exception.
    However, the table is there and I have copied the name (also deleted it and created it again, renamed it as a bounch of other names).

    The row Im currently trying to select is one that I created about a week ago. I have also tried to restart the PC and tried to brouwse on the internet for anything of this.

    public static List<Checklist> Conversie(DataSet ds) { List<Checklist> Checklists = new List<Checklist>(); //Create a row of the data and import all of the data foreach (DataRow dr in ds.Tables[0].Rows) { Checklist checklist = new Checklist(); checklist.Checklistnumber = Convert.ToInt16(dr["ID"]); checklist.Question1 = Convert.ToBoolean(dr["question1"]); checklist.Question2 = Convert.ToBoolean(dr["question2"]); checklist.Question3 = Convert.ToBoolean(dr["question3"]);

    // The problem... checklist.Tester = Convert.ToString(dr["Checklist date"]); // Trows out the execption at preveous line.. //checklist.Datedue = Convert.ToDateTime(dr["DateD"]); checklist.CompanyName = dr["Checklist.CompanyName"].ToString(); Checklists.Add(checklist); } return Checklists; }

    // THE DATABASE CONNECTION FILE IN A DIFFRENT CLASS

    using System;
    using System.Data;
    using System.Data.OleDb;

    namespace DBaccess
    {
        public class DBaccess
        {
            private static string _connectionString;

            public static string ConnectionString
            {
                get { return DBaccess._connectionString; }
                set { DBaccess._connectionString = value; }
            }
            
            static DBaccess()
            {
                string mdffile = @"..\..\..\Database\Checklist.accdb";
                ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + mdffile + ";";
            }

           public static DataSet KlantenEnReserveringenquery(string sqlStmnt)
         {
              DataSet ds = new DataSet();
                Console.WriteLine(sqlStmnt);
                OleDbConnection con = new OleDbConnection(ConnectionString);

                OleDbDataAdapter dap = new OleDbDataAdapter(sqlStmnt, con);
                dap.Fill(ds);
                return ds;
            }

            public static DataSet Getwaardenquery(string sqlStmnt)
            {
                DataSet dataset = new DataSet();
                Console.WriteLine(sqlStmnt);
                OleDbConnection con = new OleDbConnection(ConnectionString);

                OleDbDataAdapter dap = new OleDbDataAdapter(sqlStmnt, con);
                dap.Fill(dataset);
                return dataset;
            }

            public static int Uitvoerenquery(string sqlStmnt)
            {
                int resultaat = -1;
                // Console.WriteLine(sqlStmnt);

                OleDbConnection con = new OleDbConnection(ConnectionString);
                OleDbCommand cmd = new OleDbCommand(sqlStmnt, con);

                try
                {
                    con.Open();
                    resultaat = cmd.ExecuteNonQuery();
                }
                catch (Exception exp)
                {
                    string x = exp.Message;
                    Console.WriteLine(exp.Message);
                }
                finally
                {
                    if (con.State == ConnectionState.Open)
                    {
                        con.Close();
                    }
                }
                return resultaat;
            }
        }
    }

    Your help is greatly appriciated. the Exception is trown out when I try to run it (F5).

    Thank you in advance,

    Chris.


All Replies

  • Tuesday, February 21, 2012 8:08 PM
     
     
    I'd put a break point on the start of the loop and see what column names are actually in the table/datarow.

    Regards David R
    ---------------------------------------------------------------
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.


  • Wednesday, February 22, 2012 5:25 AM
     
     

    The column you mentioned is ChecklistSPACEdate.  Is it Checklist.Date?

    Or can you please give the table description and your select query, so it is easier for us to understand.


    Resolving n Evolving in C# (http://jeanpaulva.com)

  • Wednesday, February 22, 2012 6:42 AM
     
     Answered
    it trows a " Column 'Checklist date' does not belong to table Table. " exception.

    Chris.

    This error usually (and almost always)pops up when you are trying to read a rowvalue by specifying a column name which actually does not exist.

    Since you are looping thru the DataTables rows and reading the values by specifying the column names,I would rather suggest you to check whether the name of the column('Checklist date') is exactly the same or else use the column index instead.

    Hope this helps you getting rid of the problem,,,!

    -=-=-=-=-=-=-=-=-=

    Learn, Earn, Enjoy..!


    Thanks, Satish Bommideni Success usually comes to those who are too busy to be looking for it.

  • Friday, February 24, 2012 8:53 AM
    Moderator
     
      Has Code

    It must be someting completly obveous what Im missing. it trows a " Column 'Checklist date' does not belong to table Table. " exception.

    public static List<Checklist> Conversie(DataSet ds) { List<Checklist> Checklists = new List<Checklist>(); //Create a row of the data and import all of the data foreach (DataRow dr in ds.Tables[0].Rows) { Checklist checklist = new Checklist(); checklist.Checklistnumber = Convert.ToInt16(dr["ID"]); checklist.Question1 = Convert.ToBoolean(dr["question1"]); checklist.Question2 = Convert.ToBoolean(dr["question2"]); checklist.Question3 = Convert.ToBoolean(dr["question3"]);

    // The problem... checklist.Tester = Convert.ToString(dr["Checklist date"]); // Trows out the execption at preveous line.. //checklist.Datedue = Convert.ToDateTime(dr["DateD"]); checklist.CompanyName = dr["Checklist.CompanyName"].ToString(); Checklists.Add(checklist); } return Checklists; }

    Just as Spartan_578 said, set a breakpoint on the bold code and check whether the column name in the DataRow exists or not.

    Best Regards


    Neddy Ren[MSFT]
    MSDN Community Support | Feedback to us

  • Friday, February 24, 2012 11:18 AM
     
     
    Try "Checklist date" column name without spaces
  • Tuesday, February 28, 2012 4:04 PM
     
     Answered

    Dear Forum,

    Sorry for not responding in a timely manner, I trew my hat at this for a day or 2 as I was so frustrated with it.
    The colum excists. I have ran the intire query in the database, and it gives me a correct statment.

    "SELECT Checklist.ID, Checklist.question1, Checklist.question2, Checklist.question3, Checklist.checklistd, Checklist.CompanyName, Companies.CompanyName FROM Checklist INNER JOIN Companies ON Companies.CompanyName=Checklist.CompanyName
    "
    and this gives me a correct table list.

    But I found the salution. It doesnt find me selecting multipule tables at once a very nice idea.
    It started giving me problems with Checklist.ID as well, as it also suddenly didnt belong to the table anymore (This worked before =.0)

    I changed my statement to select * from checklist and now it works.
    I should stop thinking so complicated and go for simple solutions.

    Thank A lot for responding so fast.

    Kind regards,


    Chris