Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET3.0 C#
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......
 
regard
Sham
Posted 30-Oct-12 22:08pm
Comments
satz_770 at 31-Oct-12 3:14am
   
Pls. explain ur problem more clearly...
shambhoo kumar at 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 at 31-Oct-12 6:59am
   
any one help me
Rate this: bad
good
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.dgv.Refresh();
 
This way you don't need to worry about behavior of dataset vs gridview etc.
  Permalink  
v4
Rate this: bad
good
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");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("Select Name,Address from Employee", con);
DataSet ds = new DataSet();
da.Fill(ds);
CustName.DataPropertyName = "Name";
CustAddress.DataPropertyName = "Address";
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = ds.Tables[0].DefaultView;
  Permalink  

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

  Print Answers RSS
0 Maciej Los 295
1 OriginalGriff 249
2 Sergey Alexandrovich Kryukov 205
3 Aajmot Sk 197
4 Sinisa Hajnal 176
0 OriginalGriff 7,800
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2014
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