Click here to Skip to main content
11,922,026 members (37,143 online)
Rate this:
Please Sign up or sign in to vote.
See more: .NET3.0 C# .NET
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 22: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
public int UID { get; set; }
public string Name { get; set; }
public DateTime Date { get; set; }
public bool Checked { get; set; }
- 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
0 OriginalGriff 493
1 Dave Kreskowiak 285
2 Sergey Alexandrovich Kryukov 243
3 Richard MacCutchan 155
4 ppolymorphe 135
0 OriginalGriff 7,231
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,356
3 George Jonsson 2,865
4 Suvendu Shekhar Giri 2,216

Advertise | Privacy | Mobile
Web01 | 2.8.151120.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2015
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