Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to display selected fields in data grid view from MSaccess table . .Can anyone help in this .
Posted

Did you read the answer from OriginalGriff to your Question "Database Retriving Code"?
Database retriving code[^]
Same principle applies, just change
myListBox.DataSource = dt;


to

myDtatgridview.DataSource = dt;
 
Share this answer
 
Comments
Raghavendra M 12-Oct-13 14:48pm    
Yes this i knw but i m having truble in displaying selected column . . & yes I red the previous soln . .
Raghavendra M 12-Oct-13 14:53pm    
try
{
//String typ = "1BHK";
string str = "select particulars,quality,quantity,boxes from additems where fno=" + fn + "and receiptno=" + rn + "";
OleDbDataAdapter DAap = new OleDbDataAdapter(str, mycon);
DataSet DS = new DataSet();
DAap.Fill(DS, "additems");
DataTable DT = DS.Tables[0];
dataGridView1.ColumnCount = 4;
dataGridView1.DataSource = DT;
dataGridView1.Columns[0].Name = "Particulars";
dataGridView1.Columns[1].Name = "Quality";
dataGridView1.Columns[2].Name = "Quantity";
dataGridView1.Columns[3].Name = "Boxes";
dataGridView1.DataMember = "particulars";
dataGridView1.DataMember = "quality";
dataGridView1.DataMember = "quantity";
dataGridView1.DataMember = "boxes";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Real Estate... ", MessageBoxButtons.OK, MessageBoxIcon.Error);

}


this is my code but it is not showing contents of table
Richard.Berry100 12-Oct-13 15:21pm    
I seldom use a dataset. What happens if you just put: dataGridView1.DataSource = DT;

and leave out all the code after that. If your select statement has 4 coulums, those should be displayed.

Also, put a breakpoint before you assign the datatable as the datasource for the dtatgridvied, and hover over the datatable. Are you sure the datatable contains data?

you could also put a statement like

MessageBox.Show("Datatable contains " + DT.Rows.Count + " Rows");
dataGridView1.DataSource = DT;
Hi,
Two line code is ok for your requirement. first all you are already write four column in your query so don't need define column name and assign data member property.


XML
DataTable DT = DS.Tables[0]

    dataGridView1.DataSource = DT;


if you need hide some column so just write the code
dataGridView1.Columns["Boxes"].Visible = false;

one more point: your query is not correct, need more space before and condition.

  string str = "select particulars,quality,quantity,boxes from additems  where fno=" + fn + " and receiptno=" + rn + ""; 

I hope that it is useful for u.

Thanks
 
Share this answer
 
v2
Comments
Raghavendra M 25-Oct-13 23:35pm    
yes thank u . . , I am trying here giving coloumn names for grid view column , for that i hav to write my above mentioned code na . if i do so , 4 columns with given name and empty records and 4 column from database are coming . Here I want records from database and I want different name for columns .

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