Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a Save buttom which saves all DataGridView content into SQL Compact 4 data table. There is also a load button which does the reverse function. It loads the SQL data table content into DGV. My problem is that It adds one extra column named "ID" at the end of my DGV. This causes Error in calculations of my cells. What SQL Compaxt command can exclude ID from loading?

What I have tried:

C#
private void btnLoad_Click(object sender, EventArgs e)
       {
           SqlCeConnection myConnection = new SqlCeConnection();
           myConnection.ConnectionString = @"Data Source=C:\Users\Dell\Desktop\DataGridView\PMinfo.sdf";

           SqlCeCommand myCommad = new SqlCeCommand();
           myCommad.Connection = myConnection;
           myCommad.CommandText = "Select * From [PMinfo]";

           DataTable myDataTable = new DataTable();
           SqlCeDataAdapter myDataAdapter = new SqlCeDataAdapter();
           myDataAdapter.SelectCommand = myCommad;
           myDataAdapter.Fill(myDataTable);

           dataGridView1.DataSource = myDataTable;


       }
Posted
Updated 24-Nov-20 8:32am

Simple: don't use SELECT * FROM - instead always list the columns you do want.

But ... you probably don't want to exclude it at all, instead list all the columns and hide the ones you don't want the user to see: Hide Columns in DataGridView Control - Windows Forms .NET Framework | Microsoft Docs[^]
 
Share this answer
 
DGV as in DataGridView? State that ID = DataKey or DataKeyName(s) and the ID co0lumn is gone.

You can also created DataBound Columns.
 
Share this answer
 
Comments
OriginalGriff 24-Nov-20 14:53pm    
That's web based GridView only, isn't it? The DataGridView control doesn't support those properties.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900