How To Read Xls File Format in Windows application and xls file Datas are inserted into Database?

Posted by Samy33 under VB.NET on 9/15/2010 | Points: 10 | Views : 6870 | Status : [Member] | Replies : 18
I am asp.net Developer.I am not familer in windows application.But in my project i need to upload the xls file into local folder and Read the xls file datas and datas in the Xls file Should be inserted into the DataBase ?How we can do in windows application?I am in need of the Code for above operation>
If You Knows Reply me its because very urgent in my project?

Thanks in advance




Responses

Posted by: Peermohamedmydeen on: 9/15/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi Samy,

If your xls file is located in some other place, which may be a website or published location over the internet you can use the webclient class.

WebClient objWeb = new WebClient();

objWeb.Proxy.Credentials = CredentialCache.DefaultCredentials;
objWeb.useDefaultCredentials = true;
objWeb.DownloadFile("http://xyz.com/Download.A.xls", "LocalA.xls");


Then we have to open and read the data from the xls.

For ExcelDataReader refer the below link and you can get the code.
http://www.codeproject.com/KB/office/Excel_DataReader.aspx


FileStream fs = new FileStream("LocalA.xls",FileMode.Open,FileAccess.Read, FileShare.Read);
ExcelDataReader spreadsheet = new ExcelDataReader(fs);
fs.Close();
DataSet ds = spreadsheet.WorkbookData;
DataGridView1.DataSource = ds;


Hope, It will be helpful.



Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santosh4u on: 9/15/2010 [Member] Bronze | Points: 25

Up
0
Down
hi
please follow below links
http://vb.net-informations.com/excel-2007/vb.net_excel_read_entire%20_worksheet.htm
http://vb.net-informations.com/excel-2007/vb.net_excel_inset_data_oledb.htm

hope above links will help you...........


Regards
Santosh

Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Samy33 on: 9/15/2010 [Member] Starter | Points: 25

Up
0
Down
I need the Windows application Upload Coding for Uploading xls file in Vb.Net.How to do the reading Xls file after upload Completed into particular folder

Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Samy33 on: 9/15/2010 [Member] Starter | Points: 25

Up
0
Down
Dim MywebClient As WebClient = New WebClient()
Dim _FileName As String = txt_UploadFileName.Text
Dim _DynamicName As String = GetDynamicName(8) & System.IO.Path.GetExtension(_FileName)
Dim _Path As String = "D:/ValGenAppXls/UploadFile/"
MywebClient.UploadFile(_Path, _FileName)



This s my coding For Uploading the xls file into the UploadFile Folder in my application.But it shows error like Could not find a part of the path 'D:\ValGenAppXls\UploadFile\'.

How can i rectify this error

Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 9/15/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Samy33,

Check it your File Path

"D:/ValGenAppXls/UploadFile/" --> "D:\\ValGenAppXls\\UploadFile\\"


Thanks,
T.Saravanan

Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Samy33 on: 9/15/2010 [Member] Starter | Points: 25

Up
0
Down
Hi T.Saravanan

After putting this path "D:\\ValGenAppXls\\UploadFile\\" instead of D:/ValGenAppXls/UploadFile/

Same Error Is thrown Could not find a part of the path 'D:\ValGenAppXls\UploadFile\'.


Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 9/15/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Are you get the path from Local System or Other System?

http://support.microsoft.com/kb/827421

Refer this link you got an idea..

Thanks,
T.Saravanan

Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Peermohamedmydeen on: 9/15/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi

Instead of this "D:\\ValGenAppXls\\UploadFile\\".
Write the path with file name like "D:\\ValGenAppXls\\UploadFile\\ValGenApp.xls"



Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Samy33 on: 9/16/2010 [Member] Starter | Points: 25

Up
0
Down
Hai Peermohamedmydeen,
I changed that Path Name But Its not uploading the Xls file into particular Folder.I need to upload a file into the folder in our application.

Please Help me for That Concept,
Thanks Regard
Samy





Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 9/16/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Are you get the file path from Local System or Server System?

http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=115
http://www.c-sharpcorner.com/uploadfile/scottlysle/uploadwithcsharpws05032007121259pm/uploadwithcsharpws.aspx //using C#

http://www.codeproject.com/KB/webservices/UploadAnyFileVB.aspx // using VB

Refer those links i hope this will helpful to you.

Cheers :)

Thanks,
T.Saravanan

Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Samy33 on: 9/16/2010 [Member] Starter | Points: 25

Up
0
Down
Hai T.Saravanan

I am getting the local file path i need to be uploading local Xls File into Particular folder and reading that Excel file datas into database

Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jackbaker on: 10/8/2010 [Member] Starter | Points: 25

Up
0
Down
Hi,

Look at this component for VB.NET:
http://www.devtriogroup.com/ExcelReader

Excel Reader .NET can read XLS files. So you will be able to get xls file data for inserting it into the Database.

Here is the code of Excel Reader usage for .NET:
Dim Wbook = New DTG.Spreadsheet.Workbook   

Wbook.ReadXLS("ExcelReaderTest.xls")
Dim WSheet = Wbook.Worksheets(0)
Dim CELL A5 = WSheet.Cells("A5")
String s = A5.Value


Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 2/22/2011 [Member] Starter | Points: 25

Up
0
Down
For this question you can use the link it contains code for both .xls and .xlsx http://vbdotnetaddict.blogspot.com/2011/01/import-excel-table-into-sql-table.html

Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 2/22/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25
Posted by: Madhu.b.rokkam on: 2/22/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
you can also refer to this link

http://csharpdotnetfreak.blogspot.com/2009/04/export-excel-data-sqlbulkcopy-aspnet.html

Thanks and Regards
Madhu

Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naimishforu on: 2/23/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Is it this much tuff??

Thanks,
Naimish
http://dotnetinterview.zxq.net/
http://naimishpandya.blogspot.in/

Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gbucsariu on: 3/29/2012 [Member] Starter | Points: 25

Up
0
Down
Check this library for reading xls and xlsx files:
www.easyxls.com
For samples see:
www.easyxls.com/manual

Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 4/3/2012 [Member] Starter | Points: 25

Up
0
Down
http://sandeep-chourasia.blogspot.in/2012/04/read-excel.html

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Samy33, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response