0

I'm getting a headache from this...hope someone can help me.

I have a Table Clienten and made 3 new colums:

  • DhrMevr
  • Voornaam
  • Achternaam

I refreshed the database, deleted the old DataSet and created a new DataSet for the updated database. However...when I try to read the Clienten table in C# code, he doesn't see the new columns. What am I missing?

Hope someone knows the trick.

Printscreen of the table-columns in the database and dataset. It looks like the 3 extra columns are added correctly

This is the code....I get the error: Invalid column name "Achternaam"

        private void FillCBClienten()
        {
             string query = "SELECT * from Clienten ORDER BY Achternaam ASC";

             using (connection = new SqlConnection(connectionString))
             using (SqlDataAdapter adapter = new SqlDataAdapter(query, connection))
             {
                 DataTable clientenTable = new DataTable();
                 adapter.Fill(clientenTable);

                 clientenTable.Columns.Add("Naam", typeof(String), "DhrMevr + ' ' + Voornaam + ' ' + Achternaam");

                 cbClient.DisplayMember = "Naam";
                 cbClient.ValueMember = "Id";
                 cbClient.DataSource = clientenTable;
             }
        } 
Mirelle
  • 11
  • 3

1 Answers1

0

Based on my test, I don't get the error like you said.

You could try the following steps to Add extra Columns and select the new data.

First, Please use the following sql query to add the column.

alter TABLE Client
Add Email NVARCHAR (50)

Second, Please add the dataset again.

Third, please right click the TableAdapter to add query, like the following:

enter image description here

Then, we could get the datatable from the tableadapter.

 private void button1_Click(object sender, EventArgs e)
        {
            TestDataSetTableAdapters.ClientTableAdapter adapter = new TestDataSetTableAdapters.ClientTableAdapter();
            DataTable table=adapter.GetDataOrderBy();
            dataGridView1.DataSource = table;
        
        }

Finally, we could see the following ordered result by age.

enter image description here

Jack J Jun
  • 5,633
  • 1
  • 9
  • 27
  • Thnx! I tried it with a new project and the old database, and I didn't get any errors as well. However, when I dragged the tabledata from the Dataset (datagridview) to the form...I had the same error again. Even after I deleted the datagridtable...I think I'm going to start over...ahhh... – Mirelle Aug 14 '21 at 08:26
  • I was thinking...the thing I did different, is that I changed the table definition, instead of the ALTER query. Do you think this is wrong? – Mirelle Aug 14 '21 at 11:26
  • Eventually I renamed the databasefile ... made a new DataSet connection and then it worked. – Mirelle Aug 14 '21 at 12:56