import csv to sql - vb.net

I have to import an csv file to SQL database table which already created (empty and has the same number of named columns). It would be great if you could suggest any tutorials or give some tips.

I assume you are using Microsoft SQL Server. Do you need to do this in a program or manually? There is a tutorial on using the bcp command for that, or alternatively a SQL command. If you need to parse the CSV file for your own code, see this previous SO question.

Related

How to transfer SQL query results to a new csv file with headers?

I want to transfer SQL query results to a new csv file. This is because I have placed my SQL query inside a loop which will generate export query results to csv file each time. I'm using MS SQL Server 2012. I don't want to take GUI option.
Sql Server is not really designed to import and export files. You can use bulk copy program but I dont think it works in tsql code (looping). You can use openrowset but you need to set a special flag that opens up your surface area of attack which some do not want to do.
The answer is SSIS (or a tool like Talend). It comes with Sql and is designed by MS as the go to tool for import and export from Sql. If you were to right click on the data base, choose tasks and then export the wizard eventually creates and executes an SSIS package.
I recommend you reconsider a GUI option.
ps - Another answer was to use save results as. I have heard of problems using this method including problems with delimiters or text qualified fields.
There are multiple ways to attain this. Either you can export the resultset using BCP or using IMPORT/ EXPORT or using CTRL+SHIFT+S (this will change the resultset to SAVE AS. Hope this may help.

Insert data using powershell

We have a static sql file which consists of insert statements;basically test data.
is it possible to execute this script using powershell on azure sql db where alwaysencrypted is enabled. We use keyvault to store the certs.
Unfortunately, PowerShell (Invoke-SqlCmd) does not support insert statements against encrypted columns at this point. The only SQL tool from Microsoft that supports such statements at this point is SSMS - please see: https://learn.microsoft.com/en-us/sql/relational-databases/security/encryption/configure-always-encrypted-using-sql-server-management-studio#param .
An alternative could be to put your test data into a CSV file and use the Import Export Wizard to import the data into the database. You could save the import job as an SSIS package, which you could execute from the command line. Here is a blog article on using the I/E Wizard for importing (and encrypting) data from a database (importing from a file would be similar). https://blogs.msdn.microsoft.com/sqlsecurity/2015/10/31/ssms-encryption-wizard-enabling-always-encrypted-in-a-few-easy-steps/
Jakub

how to import csv file into table of sql server other than BUIK INSERT

I googled the solution online and most of the result comes back with BULK INSERT, I don't have the access to this role at this point so this is not an option.
Is there any other generic way to import .csv file into MS SQL SERVER?
I believe you need to use either SSIS or bcp if you don't have bulk insert rights. Although I would be open to learning another way.
Solution I've done the last few times I've needed to do this was save the CSVs as .XLS in excel and then pull it in from SSMS.
Edit: Here's a SO answer that shows how to do it
what I end up doing is go to task--->import, this is the original DTS functionality and it does give me option to import excel file.

any way to import csv file to firebird from sql cmd?

I need to import few columns from csv file into firebird temp table
but not using any tool only from sql editor aka openrowset in SQL server.
is it supported?
thanks
firebird doesn't have a load statement, but several tools have an import module. Easest is to edit the file into a set of insert statements
You can have look at Data Transformer (disclaimer - I'm its developer). It can convert between CSV (an other formats) to SQL. The generated SQL contains "insert" statements for each line and a "create table" statement.
It works offline - the data never leaves your computer.
You can get it from the Mac App Store or the Microsoft Store.

Can You Import an Excel File to a MySQL Database using phpMyAdmin?

Can You Import an Excel File to a MySQL Database using phpMyAdmin? I am looking to buy this database that has the data of all Colleges and Universities in the US. The file is in Excel format. Can this be imported into phpMyAdmin?
Here is the site where I am going to buy the database from if this is possible: http://www.data-lists.com/universities-colleges-database.html?gclid=CPGXkN6H6aECFeQc5wodBFPRIg
You can download a sample of the database that has 10 entries. I have tried importing this into phpMyAdmin but this is the error I am getting:
There is a chance that you may have
found a bug in the SQL parser. Please
examine your query closely, and check
that the quotes are correct and not
mis-matched. Other possible failure
causes may be that you are uploading a
file with binary outside of a quoted
text area. You can also try your query
on the MySQL command line interface.
The MySQL server error output below,
if there is any, may also help you in
diagnosing the problem. If you still
have problems or if the parser fails
where the command line interface
succeeds, please reduce your SQL query
input to the single query that causes
problems, and submit a bug report with
the data chunk in the CUT section
below:
----BEGIN CUT---- eNrtXAtsHMd5nt177R0FipQoiXqvICkiJd7xnnwJBnWiqFdIiubRjyQO5NVxSV51vGPuIYltVNNt
CgS1azhSIre20sBNXLRp2jSOm9iIW8stYLcA3RZtmodjN3Zgp3FdtLWbokVg+/rPzO7evnkXyYna
zhyHd/PvzP/N/PPP7Mw+vtGpqVNTQ+JITByJi2OjE0NiTIyLqYFkNBnKTMOR9lAoczuI95yYGRLL
H8svSqWyXIrkc2cii/OLYiyWiiXEeDQ6EIa/+IAY6xuK9Q+lEh8W8/LCoLgnNL6UuXVsSExFopH+
And then at the bottom of the error it says:
1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server
version for the right syntax to use
near 'ÐÏࡱá' at line 1
Any help is greatly appreciated.
It looks like you are trying to import a binary file.
Try to export a sheet or a range of the excel file as a CSV file. This must be a reactangle with the same structure on every row.
I've downloaded the sample data and it looks pretty organized. Just save the excel file into csv (File -> save as). Then import it using PHPMyAdmin. I think it will work perfectly fine.
Good luck! :-)