Hi..
I want to save excel sheet data in database table by using of asp.net and c#.net
Please help me
Hi..
I want to save excel sheet data in database table by using of asp.net and c#.net
Please help me
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.
Anish KhanPosted May 30, 2009, 1:47 AM
Thanks for reply
But it's not working..
and where is the code for saving the file in database..
Suchit KhannaPosted May 27, 2009, 6:53 AM
Declare all these variables in your code--
#region Declration of the members of Type ProcessExcel
private static string _sSource = ConfigurationSettings.AppSettings["Source"];
private static string _sDestination = ConfigurationSettings.AppSettings["Destination"];
Excel.Workbook _oWbook;
Excel.Worksheet _oWSheet;
ImageList list = new ImageList();
DataSet ds = new DataSet();
DataSet Required = new DataSet();
string SheetName1,SheetName2;
String Xml = null;
#endregion
#region WorkBook Variables
private static object vk_missing = Missing.Value;
private static object vk_visible = true;
private static object vk_false = false;
private static object vk_true = true;
#endregion
#region Open WorkBook Variables
private static object vk_update_links = 0;
private static object vk_read_only = vk_true;
private static object vk_format = 1;
private static object vk_password = vk_missing;
private static object vk_write_res_password = vk_missing;
private static object vk_ignore_read_only_recommend = vk_true;
private static object vk_origin = vk_missing;
private static object vk_delimiter = vk_missing;
private static object vk_editable = vk_false;
private static object vk_notify = vk_false;
private static object vk_converter = vk_missing;
private static object vk_add_to_mru = vk_false;
private static object vk_local = vk_false;
private static object vk_corrupt_load = vk_false;
#endregion
#region Close WorkBook Variables
private static object vk_save_changes = vk_false;
private static object vk_route_workbook = vk_false;
#endregion
And here is the code to open an Excel file:
Excel.Application _oXL = new Excel.ApplicationClass();
_oWbook = _oXL.Workbooks._Open(file.FullName,vk_update_links,vk_read_only,vk_format,vk_password,vk_write_res_password,vk_ignore_read_only_recommend,vk_origin,vk_delimiter,vk_editable,vk_notify,vk_converter,vk_add_to_mru );
To get to any particular sheet in the Workbook the code goes like:
_oWSheet = (Excel.Worksheet)_oXL.Worksheets.get_Item("[Worksheet name]");
and to access any data in the Worksheet, make use of get_Range( )-->
Example:
Convert.ToString(_oWSheet.get_Range("K4","k4").Text);
Hope this helps you....
Anish KhanPosted May 27, 2009, 3:55 AM
hi..
Thanks for reply...
Dear Suchit, I have a fixed excel file to upload in sql server
Suchit KhannaPosted May 27, 2009, 1:29 AM
Do you have a fixed template of excel files to be uploaded or different different excel files.... as I have a test application that consumes data from excel files with fixed template and put the data into SQL Server.. If you could specify that, I could guide you in right direction as much as I know.... :-)
Anish KhanPosted May 27, 2009, 12:59 AM
Hi..
Thanks for reply..
Actualy I want to upload excel file in dataabase
using C# .Net ..How can I do it.....
Suchit KhannaPosted May 26, 2009, 12:24 AM