Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i insert data into table???

Status
Not open for further replies.

JasonLiew

Programmer
Oct 15, 2001
37
SG
Hi there....

How am i going to insert data into my database table using sql statement.??? I'm currently on a project using ODBC to access my daatbase....Please enlighten mi...my data include 5 string data and one integer data...

regards,
Jason
 
Jason,

as liziyu sugested, ado is the way to do it..
a quick tutorial:

There are 2 libraries you could use for this:
Microsoft ActiveX Data Objects (version) Library
or
Microsoft ActiveX Data Objects Recordset (version) Library

The first is a complete set of objects (ADODB) the second is a simplified verion (ADOR)

My example uses the first library.

--CODE--
'Needed ADODB objects
Dim oRs As ADODB.Recordset
Dim oCon As ADODB.Connection

'Needed strings
Dim strSQL As String
Dim ConnString as String
ConnString = "Provider=MSDASQL.1;Persist Security _
Info=False;User ID=admin;Data Source=ODBCNAME"
strSQL = "INSERT INTO Name _
SELECT a.id, a.name, use _
FROM 3Name a, 3ReplaceCompanyid b _
WHERE a.companyid = b.id"

'Preparations (making the connection,..)
Set oCon = New Connection
oCon.ConnectionString = ConnString
oCon.Open
Set oRs = New Recordset
oRs.CursorLocation = adUseClient

'Here's where you actually perform the SQL
oRs.Open strSQL, oCon, adOpenKeyset, adLockBatchOptimistic

'clean up
Set oRs.ActiveConnection = Nothing
Set oCon = Nothing

--/CODE--

regards,
Johan
 
Thanks liziyu and johpje.
I have successfully done my project.
Thank you once again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top