Click here to Skip to main content
13,560,107 members
Rate this:
Please Sign up or sign in to vote.
See more:
i m getting problem in showing data in gridview column........actually i have 4 column in my datagridview , when i retrive data from database and store data in dataset and when i connect dataset to datarid view then it create 4 new column but i want to show data in existes column......

so plz help me......

Posted 30-Oct-12 21:08pm
satz_770 31-Oct-12 3:14am
Pls. explain ur problem more clearly...
Shambhoo kumar 31-Oct-12 3:19am
i m showing data in gridview from dataset..
and i have already created 4 column but when i retrive datafrom data set then it create 4 new column and showing record ,but i want to show record in existens column
Shambhoo kumar 31-Oct-12 6:59am
any one help me
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I would programmatically add the records in the dataset to the datagridview.
For example like this:
- Create class that matches a record (with properties matching the fields)
Class OneRecord<br />
{<br />
  public int UID { get; set; }<br />
  public string Name { get; set; }<br />
  public DateTime Date { get; set; }<br />
  public bool Checked { get; set; }<br />
}<br />
- Create BindingList of this class
Private BindingList<OneRecord> MyList = new ...
- Reference DataSource of datagridview to instance of BindingList
this.dgv.DataSource = this.MyList;
- Add records to instance of BindingList as instances of the class, need some logic for this
- Refresh datagridview

This way you don't need to worry about behavior of dataset vs gridview etc.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I solve my self........

SqlConnection con = new SqlConnection("Data Source=.; Initial Catalog=sham; Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("Select Name,Address from Employee", con);
DataSet ds = new DataSet();
CustName.DataPropertyName = "Name";
CustAddress.DataPropertyName = "Address";
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = ds.Tables[0].DefaultView;

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04-2016 | 2.8.180527.3 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100