C# .NET - the above code is working fine - Asked By Priyanka on 06-May-11 11:33 PM

OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db2.mdb");

OleDbDataAdapter adp = new OleDbDataAdapter("select * from Table1",cn);

DataSet ds = new DataSet();

adp.Fill(ds, "dataset");

dataGridView1.DataSource = ds.Tables[0];

dataGridView1.Refresh();



the above code is working fine when i have not created column in the design view but when i already have created the column in the design view this is not working ..  my question how to show data in the column that is created in the design view.. column name is column1..
Nikhil Mahajan replied to Priyanka on 06-May-11 11:40 PM
To get what you want, you should set AutoGenerateColumns property to false.
This tells the DataGridView do not generate extra default columns for the
datasource, and you take care of the column generating.

Then you should set the  added columns' DataProperyName property to
corresponding DataColumn.ColumnName.

Hope this helps
Priyanka replied to Nikhil Mahajan on 07-May-11 12:15 AM
 sir i didn't get ur these two lines :
Then you should set the  added columns' DataProperyName property to
corresponding DataColumn.ColumnName.

can u explain it with example?
Asked By Priyanka on 07-May-11 12:21 AM
with this code grid view is not generating new columns but the values are not coming in the column1 that is created in the desingn view..
Nikhil Mahajan replied to Priyanka on 07-May-11 12:23 AM
in design view of datagridview...

1. at right top side of datagridview there is arrow sign..

2. click on it there you will see add new column..

3. on left side you will see list of column you created in datagridview.

4. now just click on any column...you will see on right side the property attributes for that column...

5. just scroll down to to find DataProperyName 
and write there the column name which u wanna bind..

ex: if your column name in database is "ab" then you will write in that peroperty "ab" without quotes...then that column will display ab column value..

hope now u clear..
Priyanka replied to Nikhil Mahajan on 07-May-11 12:45 AM
thanks......