If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Challenging insertation operation ..Plz Help me

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-17-04, 13:07
Mahfuz Mahfuz is offline
Registered User
 
Join Date: Nov 2003
Location: Dhaka,Bangladesh
Posts: 86
Question Challenging insertation operation ..Plz Help me

Hello VB experts,

Recently I am facing a problem for insertion data in MS access database using ADO from VB...Its like:

my table is like

Id name Dept
-- ----- -----

Now from VB i have 3 array holding value like

i[10] = { 10 20 30 40 } ' For ID
n[10] = { 'A' 'B 'C' 'D' } ' For Name
d[10] = { 'CSE' 'BBA' 'EEE' 'MBA'
}

now i want to insert data for output

Id name Dept
-- ----- -----
10 A CSE
20 B BBA
30 C EEE
40 D MBA

Now i tried it for ADO's recordset .ADDNEW and .Update properties but failed.
Can any body help me any sQL command or any other tricks..Plz i m facing a challenging Problem in it. Plz help me as quick as possible.

Thnaks a Lot.

mahfuz
__________________
hello
Reply With Quote
  #2 (permalink)  
Old 08-18-04, 08:08
vududoc vududoc is offline
Registered User
 
Join Date: Jul 2001
Location: NC
Posts: 102
please note this is but a guide. It assumes that all arrays are of equal length. While ID is not a computational field, you have specified the data to be numeric, and not a text number. "n" and "d" are character strings.


dim xConx as ADODB.connection
dim iCnt as integer
dim strSQL as string
dim maxArray as integer

<make ADODB connection>

on error goto INSERTERROR
for iCnt = 0 to maxArrary -1 step 1
strSQL = "INSERT INTO <tablename> (id, name, dept) VALUES " & _
"(" & i(cnt) & ",'" & n(icnt) & "','" & d(icnt) & "')"
xConx.beginTrans
xConx.execute strSQL
xConx.committrans
next
<drop connection>
on error goto 0
exit sub

INSERTERROR:
xConx.rollbacktrans
<drop connection>
on error goto 0
exit sub
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On