Click here to Skip to main content
12,950,399 members (63,107 online)
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
OriginalGriff 5,829
CHill60 3,460
Maciej Los 2,953
Jochen Arndt 1,975
ppolymorphe 1,820

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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