How to insert Excel sheet file into SQL Server database? - asp.net

I have an Excel sheet with more than 1000 records with customer details such as name, tele, address ...etc. and I want to know if I can save this sheet into a SQL Server database without inserting these records one by one from an aspx page, as I will have table in the database with customer details.

You can use SSMS's Import Data option, and use Excel as a data source and the table as the destination. This is a "run once" option. The second option, if you have to run this frequently, is to create an SSIS package for the import.

Related

how to export queried result from db browser sqlite to google drive

i have a table with over six millions rows and i want to query them and save the result as a google sheet document but I don't know how.
as well I would like to know how to save the result as a new table in the database
This code here should be able to make a new table from your query.
CREATE TABLE new_table AS
SELECT expressions
FROM existing_tables
[WHERE conditions];
Regarding the data transfer I would recommend using a converter website, like sql to xlsx and then opening the xlsx file in Google drive, that's at least how I move data from SQL to Google drive or Excel.

Export SQL Results to an excel file - Teradata Studio Express

Teradata Studio Express, Version 16.2
I queried from an oracle database using TSE's SQL file editor (Since it is a non-TeraData database or else I would be using TSE's Teradata SQL editor). When querying from SQL File Editor, TSE provides the result within the SQL Results panel.
What I want to do is to export the result to an excel file but it does
not provide an option to do so. How do I approach this?
Below is a screenshot comparing result set panels. The left panel (querying from Teradata SQL Editor) has an option to export to excel but the right panel (Querying SQL File Editor) does not.
Finally figured it out.. Don't know why they don't provide a export option icon yet but here is solution:
Right click on the result table.
It will provides options. Select Export, then Current Result...
Then this window will appear (save it as a csv file and you should be able to open with Excel):

How to add new column in SQL Server using SqlBulkCopy which is not present in Excel using asp.net

I am creating an application which will upload data from Excel to SQL Server using ASP.NET. I know how to upload Excel data using SqlBulkCopy. But I am trying to upload some extra data for the table column (addeddate, addedby...etc) which is not present in the Excel sheet.
I get this error:
The given ColumnName '18-01-2016 17:24:07' does not match up with any column in data source.
You can try below solution to insert constant values like addeddate, addedby...etc.
SELECT
EXCEL_COL1,
EXCEL_COL2,
'newconstantvalue' as CustomCol
FROM
ExcelSheet1
Then
bulkCopy.ColumnMappings.Add("Table_COL3", "CustomCol");
Please refer the article for more detail.

How to read from a file using asp.net

I have Uploaded a file into server and I want to read the data from that file and insert data into the oracle. I am using a list for taking the data from the file and Data is reading from this List. No problem with my code. It reads completely and data's are inserted into the oracle table Locally.. But After Hosting the data's not completely inserted to the table..After inserting some data it become stuck.

how to insert values from an excel sheet to sqlserver 2005

i have an excel sheet where i try to upload my excel sheet to sqlserver all having same colum name.
now i do not want to add dll files as an web reference in my project.
rather place the (dll) in an folder and call them dynamically in .cs side.
now i am doing like this
var assembly = Assembly.LoadFrom(#"d:\abc\microsoft.office.interop.excel.dll");
now in my .cs page i need to generate this property or methods of an excel dll which i have loaded dynamically
microsoft.officce.interop.excel.applicationClass excel= null
so that after loading my excel dl dynamically i need to sent values from my excel sheet to sqlserver 2005
is there a way to achive this
thank you
Can you not use OPENROWSET?
i.e Create a stored procedure that takes the path of the excel file which you want to insert into a given table. Use OPENROWSET function inside it to get a hold of the excel sheet.
Aother option is to possibly use SSIS to do this (SQL Server Integration Services). You would have more flexibility and could turn it into a small ETL project.
You could also use Excel code to transmit the data to the database either with a button or a macro. That only works if you can control the Excel file.
Just throwing other options out there.
First add a linked server to your Database instance..
Exec sp_dropServer 'myExcel',#droplogins='dropLogins'
EXEC sp_addlinkedserver 'myExcel',
'ACE 12.0',
'Microsoft.ACE.OLEDB.12.0',
'D:\SAABZX01D\EXCEL_books\ExpressLane\LMI\client carrier conversion.xls',
NULL,
'Excel 12.0'
exec sp_linkedServers
Then you insert to myTable in yourDatabase
Insert myTable(cola,colb,colc)
select cola,colb,colc from openQuery(myExcel,'select cola,colb,colc) from sheet1$')
You can open an excel file like a database (described here). After this you can load the data into some DataSet (I hope you know how to work with datasets) and upload all to the SqlServer database or to load in some custom structures, update some data if need and insert it into SqlServer database.

Resources