Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 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......

regard
Sham
Posted
Comments
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

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.dgv.Refresh();

This way you don't need to worry about behavior of dataset vs gridview etc.
 
Share this answer
 
v4
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;
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900