Link to home
Start Free TrialLog in
Avatar of SmashAndGrab
SmashAndGrab

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial