c# sending data from excel to SQL database - c#

I want to be able to send data from an excel file to an SQL database.
The Excel file only has one column and will always be this way.
I am currently working on a project where people will place excel files into a folder which will need to be read and put into sql, I am able to monitor the folder currently and am able to capture the file name of that file to a variable which i can call to select the excel file.
What i cannot find is a simple excel to sql tutorial that doesnt rely on the import wizard.
If you are able to help please do and if you want any further information please feel free to ask
Thanks alot :)

Related

Import csv file content to SQL Server using C#

I have an Excel file on my desktop, and I would like to use C# to insert Excel content to SQL Server, how sould I do? (use Entity Framework and console to complete it)
I use windows application(.NET Framework) and use code first to build my model.
Now I had build the table in SQL Server but I'm not sure how to read Excel file from desktop and insert data in excel file to SQL Server.
I just find Excel file from desktop then I don't know what should I do for next step.
string path = #"\Users\chun0\Downloads\filename.csv";
string input = File.ReadAllText(path);
Could anyone help me?
Thank you all so much.
This is, step by step, explanation of doing just what you ask, if I got it correct. https://www.c-sharpcorner.com/article/import-excel-data-to-database-using-Asp-Net-mvc-entity-frame/

How to update data in excel File using C#?

This Question might be repeated, But I couldn't get solution regarding my problem so far. I'm new to Interop. I'm using excel file (as a database).
Here is data presentation in excel file
in my data If Card ID repeated then I need to increment '1' in Counter in the same row, similarly I need to fetch IP address of same row..
I'm using Interop Excel approach to insert data in excel file..
Kindly tell me how can I perform that update operation to that excel file through C# (WPF)
Sorry for bad English..
Thanks
I recommend using Closed XML
You write to the file directly and don't need Excel. It will need to be the latest version of an Excel file to work (The open xml standard).
Epplus.dll or npoi.dll will also read/write to excel files w/o excel.
Save the data in an XML or JSON file, then when you want to visualize them you create the excel file from these data, so you will have a very light file and easy to read and update if you wish.
I haven't done this specifically through wpf, but you can access powershell cmdlets through .net and powershell has commands for retrieving and writing Excel data.
That said, my experience has been it's very tedious and inconsistent with bugs. I would tell your client that using an Excel file as a database is impossible and certainly prone to failure in practice.
For one thing you will run into read/write restrictions if it is used by anything else.
If you don't mind to use comercial libraries, you can try to use Aspose.Cells. It has rich cells API and able to work without Excel interop API.

Pull Data from an excel sheet, based on a textbox contents

Okay, I'm currently writing an Audit program for the company I work for to allow us do Audits easier than our current process.
PROBLEM:
I'm struggling to get or find a way for VB to reference a stock file (Excel, can be converted to txt delimited files etc.) with a barcode(column 1), and pull a code(column 2) and the description(column 3) from it and put that data in two other text boxes.
I'm currently using a Windows Form Application, so C#.
Could someone please point me to an article or explain how to go about this?
Option:
Connect to the excel via oledb.
Reading excel file using OLEDB Data Provider
Option:
Convert the excel file to a txt file, and read it with StreamReader.

Reading particular columns of Excel sheet

I need to read particular columns from an Excel sheet (say Columns A,P,Q,B) and also some particular cells (say C3 or D10). I do not need it to be displayed in a DataGrid view or anything (all examples I have seen use DataGrid).
How do I do that and write them into a new CSV file?
I have no sample code as I do not know how to proceed.
I sugest you use the ExcelReaderInterop library.
using Microsoft.Office.Interop.Excel;
Detailed example can be found here:
http://www.dotnetperls.com/excel
I had to deal with a similar issue a few weeks ago and could not find a simpler way to deal with this. The post suggest this overkill approach may be due to lots of legacy code in the library.
We have successfully used the Microsoft Access Database engine to open and read Excel files. The "2010 Access Redistributable" can also be installed on a server free of charge. What you asking for is a multi-step process:
Open a connection to the file using the Access OleDbConnection. In the connection string the "Data Source" is the file name.
Select the appropriate worksheet, which will return a DataTable object.
Grab a row from the data table or iterate over top of all of them myDataTable.Rows.
Access the column in question.
This post shows some of the process:
SSIS Excel Source Connection. What does it use to read Excel?
Hopefully this gets you pointed in the right direction.
I copied the columns that I needed to another excel sheet and saved it as CSV. Then read this csv to perform the task.
This was the easiest option as the machine I was suppose to run the program didn't have Microsoft office.

Using SQL Bulk Copy to fill a database table

I'm working on an web app using ASP.NET MVC4. I have an Excel file with several columns (some of them are useless) and I'd like to export the data to a related table by uploading the file.
One of my superiors told me to use SQL Bulk Copy to do that. I search some information about that but nothing really interesting (for example, nothing about how to map the excel columns and the table fields).
Any idea/tutorial to do that?
Hello friend please review this article, i think it will contains all the required information you needed. but you need to do some modification as per your requirement.
SQLBulk insert from Excel
if you are facing any connection issue with your Excel workbook, please modified your excel connection string for that there is a good article provide all the necessary information regarding Excel connection string
Excel Connection String Sample

Categories