How to display some columns of database
i have database and i don't want to load all columns how can i go about it so that datagrid will select columns on form load
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankaj Kumar ChoudharyPosted Mar 5, 2015, 7:17 AM
SqlCommand com = new SqlCommand("select * from TblMaster_Main_Category",con);
//This query will return a collection of all column of table TblMaster_Main_Category
SqlDataAdapter da = new SqlDataAdapter(com);
DataTable tab = new DataTable();
da.Fill(tab);
//WE take a new table
DataTable tab2 = new DataTable();
DataRow[] tb=new DataRow();
tb= tab.Select("select Serial_Order,nvCategory_Name");
// this query return a collection of all column which you want to select
foreach (DataRow dr in tb)
{
tab2.Rows.Add(dr);
}
tab2.AcceptChanges();
// Now you can Binf this table to your gridview