周末没上线,今早才看到你的消息
Option Explicit
Dim CNN As New ADODBConnection
Dim Rs As New ADODBRecordset
Private Sub Form_Load()
Dim Cnstr As String, I As Integer
'设置数据库连接
Cnstr = "Provider=MicrosoftJetOLEDB40;"
Cnstr = Cnstr + "Data Source=" + AppPath & "\XXMDB;"
CNNConnectionString = Cnstr
'读取combo(0 - 4)下拉列表
CNNOpen
RsOpen "select 品种 from TT", CNN
Do While Not RsEOF
For I = 0 To 4
Combo1(I)AddItem RsFields(0)Value
Next I
RsMoveNext
Loop
RsClose
CNNClose
'请选择
For I = 0 To 4
Combo1(I)Text = "请选择品种"
Next I
End Sub
Private Sub Command1_Click() '显示
Dim I As Integer
List1Clear
For I = 0 To 4
If Combo1(I)Text <> "请选择品种" Then
List1AddItem Combo1(I)Text
End If
Next I
End Sub
Private Sub Command2_Click() '排序
Dim I As Integer, J As Integer
List2Clear
For I = 0 To List1ListCount - 1
For J = 0 To List2ListCount - 1
If Val(Left(List2List(J), 2)) >= Val(Left(List1List(I), 2)) Then Exit For
Next J
List2AddItem List1List(I), J
Next I
End Sub
'其实排序这里有个不费脑筋的办法,只要在窗体设计时把list2的sorted属性设为TRUE,它就会把添加进来的数据自动排序
Private Sub Command3_Click() '查询
Dim I As Integer, N As Integer
If Text1Text = "" Then
MsgBox "请填写间隔数。", vbOKOnly, "提示"
Exit Sub
End If
N = Val(Text1Text)
List3Clear
CNNOpen
For I = 0 To List2ListCount - 1
RsOpen "select from TT where 品种 ='" + List2List(I) + "'", CNN
If 1 + I N <= 9 Then
List3AddItem RsFields(1 + I N)Value
Else
List3AddItem RsFields(9)Value
End If
RsClose
Next I
CNNClose
End Sub
查询语句用"select",最简单的就是直接用以下语句:
sql:select from tablename;从表“tablename”中查询出所有的数据。
扩展:后面还可以增加“where”条件进行筛选。
sql:select from tablename where id<5;查询出id小于5的所有记录。
在“查询”按钮中写查询程序
SQL="SELECT FROM TATLENAME WHERE 物质名称 ='"&trim(text1text)&"'"
rsopen sql conn,1,3
if rseof=false then
text2text=rs("value")
end if
If rsFields("姓名") Like "" & LCase(NameQuery ) & "" Then
不需要这样做的,下面的代码要好些
NameQuery = InputBox("请输入要查询的名字", "查询")
Set rs = con3OpenRecordset("SELECT FROM 通讯录 where 姓名 = '" & trim(NameQuery) & "'")
if not rseof then
Txtname = rsFields("姓名")
TxtE_mail = rsFields("E_mail")
Txtmobil = rsFields("手机")
TxtQQ = rsFields("QQ")
Txtphone = rsFields("固定电话")
else
MsgBox "查无此人", , "注意"
end if
以上就是关于求助:VB数据库查询全部的内容,包括:求助:VB数据库查询、VB中怎么写数据库查询语句、VB 6.0的数据库查询等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)