By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,345 Members | 1,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,345 IT Pros & Developers. It's quick & easy.

.exe to insert data in SQLServer database

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
ADO 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
--
Jul 20 '05 #2

P: n/a
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" <sa********@supereva.it> wrote in message
news:94*************************************@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

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.