dbTalk Databases Forums  

.exe to insert data in SQLServer database

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss .exe to insert data in SQLServer database in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Santo Santis
 
Posts: n/a

Default .exe to insert data in SQLServer database - 07-05-2004 , 03:35 AM






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

Reply With Quote
  #2  
Old   
David Portas
 
Posts: n/a

Default Re: .exe to insert data in SQLServer database - 07-05-2004 , 05:59 AM






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
--



Reply With Quote
  #3  
Old   
John Bell
 
Posts: n/a

Default Re: .exe to insert data in SQLServer database - 07-05-2004 , 02:57 PM



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 (AT) supereva (DOT) it> wrote

Quote:
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



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.