VB accesc获得总列数

来源:百度知道 编辑:UC知道 时间:2024/05/25 00:01:56
我是用VB + DATA + ACCESS 做的数据库.
VB数据
k=1
for a=0 to 9
for b=0 to 9
q1(k)=a
q2(k)=b
k=k+1
next b,a
Access数据库:
期号 数1 数2
01 2 3
02 5 9
03 9 0
04 4 2
05 7 2
06 9 7
07 2 0
08 1 3
09 8 9
10 2 7
11 3 9
. . .
. . .
. . .

请问:
1.如何自动获得总列数,如上."11"(增加数据后自动增加)
怎样写代码?
2.如何表达查询语句?
如:

Private Sub Command1_Click()

Data1.Recordset.MoveLast
for k=1 to 100
for i="总列数" to 1 step -1
if q1(k)=Data1.Recordset.FindPrevious "数1" and q2(k)=Data1.Recordset.FindPrevious "数2" then

请问:(Data1.Recordset.FindPrevious "数1") 该如何表达,我这样写错的?

删除q1(k),q2(k)
next i
next k

3.我用一个label 来显示期号,如何让它自动增加显示.
如:
在我输入第10期后.Label 自动加1,显示为11.

4.我

我看你的代码看的非常莫名。不知道你想干嘛
1.关于总列数的问题,我的意见是:多用loop语句。
recordset对象有一个eof属性和一个bof属性,他们用来确定是否在末尾、开头,所以你可以这样写

recordset1.movefirst
do until recordset1.eof
k=k+1
recordset1.movenext
loop
这样得到总列数k

像这句话for i="总列数" to 1 step -1
不如这么写:
do until recordset1.bof
...
recordset1.moveprevious
loop

2.不懂你说明什么问题。貌似recordset没有findprevious这个功能嘛

3.这个简单,比如你在一个文本框输入
Private Sub Text1_Change()
Label1.Caption = CInt(Val(Text1.Text)) + 1
End Sub

4.其实这个问题我还是没看懂。。不过根据我的理解,一般应该这样:
With recordset1
.AddNew
!期号= Text1.Text
!数1 = Text2.Text
!数2 = Text3.Text
.Update
End With

如何当增加的下一项没有输入数据时,就不再增加,即增加按钮无效.
我的理解是:
if text1.text="" and text2.text="" and text3.text="" then
recordset1.cancelupdate
msgbox "一定要有数据!"
end if

5.dbgrid没用过。也没