Friday, February 24, 2012

.exe to insert data in SQLServer database

How can I make an .exe file that can insert data automatically in a
SQLServer database, I can do it in C, but how can I connect to SQLServer
and execute a query.

All data that I have to insert are data that I can have from PC
environment variables.

Thanks

--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORGADO or ADO.NET is the API most commonly used to connect to SQLServer from
C++ and other languages. You can use the ADO Command object to execute any
SQL statement, including INSERT statements to insert new data. Lookup ADO in
SQL Server Books Online for some examples.

--
David Portas
SQL Server MVP
--|||Hi

There are various ways to do this if you want to look at a programming
language such as VB then check out the examples that come with the SQL
Server installation. If you want a simple way to do it then you could use
the osql/isql utilities that are shipped with SQL Server. Check out books
online for information on all of these things. An example using osql on the
command line to access environment variables:

C:\>set Name=Fred

C:\>echo %name%
Fred

C:\>osql -E -dTest -S"(local)" -Q"CREATE TABLE Tmp1 ( name varchar (20) )"

C:\>osql -E -dTest -S"(local)" -Q"INSERT INTO Tmp1 ( name ) VALUES (
'%Name%' )
"
(1 row affected)

C:\>osql -E -dTest -S"(local)" -Q"SELECT * FROM Tmp1 "
name
-------
Fred

(1 row affected)

You could also put this into a batch file.

If you are looking to import data in bulk then look at the bcp utitlity or
the BULK INSERT statement.

John

"Santo Santis" <santosanto@.supereva.it> wrote in message
news:94650d3133425f4d14afaeb82a2328e1.114479@.mygat e.mailgate.org...
> How can I make an .exe file that can insert data automatically in a
> SQLServer database, I can do it in C, but how can I connect to SQLServer
> and execute a query.
> All data that I have to insert are data that I can have from PC
> environment variables.
> Thanks
>
> --
> Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

No comments:

Post a Comment