472,127 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

.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.ORG
Jul 20 '05 #1
2 2671
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
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.

Similar topics

2 posts views Thread by Jan van Veldhuizen | last post: by
1 post views Thread by =?Utf-8?B?VGFudGFsdXM=?= | last post: by
4 posts views Thread by Rick | last post: by
4 posts views Thread by =?Utf-8?B?U2FpbXZw?= | last post: by
7 posts views Thread by anu b | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.