| |

VerySource

 Forgot password?
 Register
Search
View: 1515|Reply: 4

How to add data to the access table in vb

[Copy link]

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-9-28 21:00:02
| Show all posts |Read mode
I wrote a program recently, but I can't write it all the time. Ask a master. I want to insert the value in an array xm (1 to 9) into the field "project name" in the table dykz in dyin.mdb, as well as other fields. The code is as follows:
dim i as integer
   i=1
  for i = 1 to 9
     insert into dykz("Project name") valuse (xm(i))
   next i
"Dykz has no end of sentence" error
Do you want to connect to the database? ? Please give me a more comprehensive and detailed code, preferably with comments, I am a novice, love to learn, please give me a little encouragement!
Reply

Use magic Report

0

Threads

21

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-9-29 14:15:01
| Show all posts
conn.execute("insert into dykz (project name) valuse ('"&xm(i)&"')"
Reply

Use magic Report

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-9-30 08:15:01
| Show all posts
Do you want to add a little statement to connect to the database? Is this only enough?
Reply

Use magic Report

0

Threads

21

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-9-30 10:00:01
| Show all posts
Click the "Project" menu and select "Reference"
Select "Microsoft ActiveX Data Objects 2.0 Libray" or above in the list

establish connection
Dim conn As New ADODB.Connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database path"

dim xm(1)
xm(0)="123"
xm(1)="321"
for i = 0 to ubound(xm)
  'Add to database
  conn.execute("insert into dykz (project name) valuse ('"&xm(i)&"')"
next i
Reply

Use magic Report

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-9-30 13:00:01
| Show all posts
Thank youpronice, but
conn.execute("insert into dykz (project name) valuse ('"&xm(i)&"')")
There is a grammatical error in this sentence, please help me see
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list