selecting data from excel sheet
-
i have to write a code for for copying a selected data from excel sheet to data grid now i m confused that whether i have to open the excel sheet with the program of had to show it to the form because i can't show the whole sheet to the datagrid (as its a requirement of a program) and after opening the sheet how i can copy the data from excel sheet display it on the datagrid any ideas ??????
-
i have to write a code for for copying a selected data from excel sheet to data grid now i m confused that whether i have to open the excel sheet with the program of had to show it to the form because i can't show the whole sheet to the datagrid (as its a requirement of a program) and after opening the sheet how i can copy the data from excel sheet display it on the datagrid any ideas ??????
Use this function
public static DataTable getDataTable(string strFilename)
{
string SQL = "select * from [Sheet1$]";
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strFilename + ";";
connectionString += @"Extended Properties=""Excel 12.0;HDR=YES;""";
OleDbConnection conn = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand(SQL, conn);
DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dt);
da.Dispose();
conn.Dispose();
cmd.Dispose();
return dt;
}Gaurav Dudeja http://www.gdinfotechindia.com
Dont be afraid of changing your life to better ! -
Use this function
public static DataTable getDataTable(string strFilename)
{
string SQL = "select * from [Sheet1$]";
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strFilename + ";";
connectionString += @"Extended Properties=""Excel 12.0;HDR=YES;""";
OleDbConnection conn = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand(SQL, conn);
DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dt);
da.Dispose();
conn.Dispose();
cmd.Dispose();
return dt;
}Gaurav Dudeja http://www.gdinfotechindia.com
Dont be afraid of changing your life to better !thnx for ur reply but it is simply the binding of excel sheet to datagrid but i have to copy selected data from excel sheet means when user click on certain record in excel sheet it gets copied in datagrid okzzz and plz do tell me also that how to open excel sheet with program for copying the data from it thnx in advance
-
thnx for ur reply but it is simply the binding of excel sheet to datagrid but i have to copy selected data from excel sheet means when user click on certain record in excel sheet it gets copied in datagrid okzzz and plz do tell me also that how to open excel sheet with program for copying the data from it thnx in advance
sorry i never do this so no idea.
Gaurav Dudeja http://www.gdinfotechindia.com
Dont be afraid of changing your life to better !