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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Suchit KhannaRank #1,100 · 1.7K reputationPosted May 25, 2009, 8:24 PM EDT
Anish Khan25 reputationPosted May 26, 2009, 8:59 PM EDT
Hi..
Thanks for reply..
Actualy I want to upload excel file in dataabase
using C# .Net ..How can I do it.....
Suchit KhannaRank #1,100 · 1.7K reputationPosted May 26, 2009, 9:29 PM EDT
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 Khan25 reputationPosted May 26, 2009, 11:55 PM EDT
hi..
Thanks for reply...
Dear Suchit, I have a fixed excel file to upload in sql server
Suchit KhannaRank #1,100 · 1.7K reputationPosted May 27, 2009, 2:53 AM EDT
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 Khan25 reputationPosted May 29, 2009, 9:47 PM EDT
Thanks for reply
But it's not working..
and where is the code for saving the file in database..