public static DataTable GetDataColumnExcel(string filename, string colomnname,string Table)
{
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + filename + "; Extended Properties = \"Excel 8.0;HDR=Yes;IMEX=1\";");
conn.Open();
string strQuery = "SELECT [" + colomnname + "] FROM [" + Table + "]";
System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter(strQuery, conn);
System.Data.DataSet ds = new System.Data.DataSet();
adapter.Fill(ds);
return ds.Tables[0];
}
dataGridView1.DataSource = dt1.DefaultView;
here the query gets the data from the excel sheet table. now i want to edit rows in particular column in that table and display to gridview. Please help me
Loading
znaneswar kodavantiPosted May 8, 2012, 8:49 AM
EhteshamPosted May 8, 2012, 7:57 AM
foreach(DataRow dr in dt.Rows)
{
dr["qualification"]="pg";
}
dataGridView1.DataSource = dt;
Make sure before binding to datasource property of gridview your Datatable contains columnname "qualification"
znaneswar kodavantiPosted May 8, 2012, 7:50 AM
EhteshamPosted May 8, 2012, 7:23 AM
//Get DataTable from grid
DataTable dt=(DataTable)dataGridView1.DataSource;
//Specify the row and column index which is needed to edit
dt.Rows[0][0]="value to display";
dataGridView1.DataSource=dt;
If you want to add new row use
DataRow dr= dt.NewRow();
dr[0]="value to display";
dt.Rows.add(dr);
dataGridView1.DataSource=dt;
Hope it helps