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
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Mar 5, 2015, 2:17 AM EST
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