Datagrid view in Winform

Hi,

I have created a datagridview in my winform.

I have part created it using the IDE (see image 1) and would like to update some of it from the database.
I can't see how I tell the datagridview to update the columns I want it to.

1. How do I update my 2 columns from the SQL into the first to columns of my datagrid?



Here is the code that I have so far but this just adds the columns from the database on the end of the datagrid which I do not want.


string cs = @WhichSystem();
        string sql = "SELECT Customer_Code,Description from MCRS_LU_Products where Product_Group like '01'"; //sql statment to display all data
        OleDbConnection conn = new OleDbConnection(cs); //connectiion
        OleDbDataAdapter da = new OleDbDataAdapter(sql, conn); //data adapter object
        DataSet ds = new DataSet(); //dataset object to keep data in table
        conn.Open(); //open connection
        da.Fill(ds, "table_name"); // fill the dataset with table_name through data adapter
        conn.Close(); //close connection
        dgCleanseData.DataSource = ds; //populate the datagridview with dataset
        dgCleanseData.DataMember = "table_name"; // populate datagridview with table_name

Open in new window



I would like:
a) Customer_Code to populate the column 'EAN' on the datagrid
b) Description to populate the 'Description' column on the datagrid.


Thank you
SmashAndGrabAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
You did not attach an image but I assume you just defined the columns you want in the IDE like this:
captureI think you can get what you want by inserting this code before you assign the DataSource (between line 8 and 9):
            dgCleanseData.AutoGenerateColumns = false;
            dgCleanseData.Columns[0].DataPropertyName = "Customer_Code";
            dgCleanseData.Columns[1].DataPropertyName = "Description";

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.