for循环里面连接mysql,通过访问数据库使用For循环

Hello everyone

Am using a For Loop to access records from my database but the code opens instead of a specific record base on values passed by the user. These values a fields in the database which i want to make keys.

This a bit of the code

Vb 6 and Microsof Access

code Vb:

If rs.RecordCount = 0 Then Exit Sub

rs.MoveFirst

For i = 1 To rs.RecordCount '' Read all the records from database

cbosch = rs("CentNo")

Cand_No = rs("IndexNo")

Sex = rs("Sex")

DOB = rs("DOB")

Cnd_Name = rs("CandName")

Grd11 = rs("Grd1")

Subj2 = rs("Subj2")

Grd12 = rs("Grd2")

Subj3 = rs("Subj3")

Grd13 = rs("Grd3")

Subj4 = rs("Subj4")

Grd14 = rs("Grd4")

Subj5 = rs("Subj5")

Grd15 = rs("Grd5")

Subj6 = rs("Subj6")

Grd16 = rs("Grd6")

Subj7 = rs("Subj7")

Grd17 = rs("Grd7")

Subj8 = rs("Subj8")

Grd18 = rs("Grd8")

''validate the Key fields (Examseries, year, candNo and index no.)

Exam_Sr = rs("ExamSeries")

If Exam_Sr = "" Then

MsgBox ("Pls enter the correct Exam Serie"), vbOKOnly

ElseIf Exam_Sr = 1 Then

frmListing.Exam_Series.Caption = "May/June"

Else

Exam_Sr = 2

frmListing.Exam_Series.Caption = "Nov/Dec"

Me.Exam_Sr.SetFocus

Me.Refresh

End If

Exam_Yr = rs("ExamYear")

If Exam_Yr = "" Then

MsgBox ("Please Enter the exam year"), vbOKOnly

Me.Exam_Yr.SetFocus

End If

It prints the fields on to another form after getting them

''Show a modal form named frmListing.

frmListing.Show vbModal, Me

rs.MoveNext

Next i

code ends

解决方案HI....

i understand your code and every thing is ok, but i didnt find your question, or i miss something???

Best Regards

Thanks for the reply

The problem is this

the for loop am using counts all the records and the prints all of the records from the database.

What i can''t do is to be able to choose record by record using the the Candidate No, Year of exam and centre No.

I just don''t how to use these three values as a key to search for a record.

Thanks for your help.

Newbie

One possibility would be to check these fields inside the For loop, to decide whether to process the record.

Generally though, you would probably want to use a WHERE clause in your SQL to determine which records are placed in the recordset. Can you show us how rs was created?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值