连接ACCESS数据库,在VB建立一个窗体,有三个文本框和一个查询按钮打印按钮,在三个文本框中输入东西,点查询出现数据在该窗体上,文本框可以为空,可以单独查询,也可以输入二个或三个查询,查不到记录有提示,谢谢!请提供示例软件,发到我邮箱里[email protected],谢谢!补充一下,有一个文本框是组合框,自动导入数据库字段值
解决方案 »
- VB 保存路径
- EXE文件出现ASCII字符
- VB生成EXCEL的程序,在EXE中运行正常,同样的程序在DLL(用于WEB)中就不正常
- win2k/NT/XP 里有没有这个路径:(Windows\)System\Iosubsys ? 该怎么判断是否为win98操作操作系统?并将一个*.dll或其它文件复制在此路径
- 寻找类似开发环境的属性列表控件!!!
- 如何实现下面的显示格式 activereport
- 谁能将这条VC语句用VB写一下? recv(ServerSock,(char*)&bitSize,sizeof(bitSize)+1,0);
- 90分寻找codemax的说明文档
- 有free的gif动画图标的控件吗?谢谢高手们的帮助。。。。。
- vb字符串的结构问题
- 同一串口,多个mscomm问题
- VB中使用move将txt文本重命名,造成进程错误的问题
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSql As String
Dim i As Integer
Dim j As Integer cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\mydb.mdb;Persist Security Info=False" strSql = ""
strSql = strSql & " select * " & vbNewLine
strSql = strSql & " from mytable " & vbNewLine
strSql = strSql & " where 1=1 " & vbNewLine
If Text1.Text <> "" Then
strSql = strSql & " and item1 = '" & Trim(Text1.Text) & "' " & vbNewLine
End If If Text2.Text <> "" Then
strSql = strSql & " and item2 = '" & Trim(Text2.Text) & "' " & vbNewLine
End If If Combo1.Text <> "" Then
strSql = strSql & " and item3 = '" & Trim(Combo1.Text) & "' " & vbNewLine
End If
rs.Open strSql, cn, adOpenStatic, adLockOptimistic If rs.RecordCount > 0 Then
With MSFlexGrid1
.Rows = rs.RecordCount + 1 While Not rs.EOF
i = i + 1
For j = 1 To .Cols - 1
.TextMatrix(i, j) = rs.Fields(j - 1)
Next j rs.MoveNext
Wend
End With
Else
MsgBox "没有数据"
End If rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End SubPrivate Sub Form_Load()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Combo1.Clear
cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\mydb.mdb;Persist Security Info=False" rs.Open "select item3 from mytable group by item3", cn, adOpenStatic, adLockOptimistic If rs.RecordCount > 0 Then
With Combo1
.AddItem ""
While Not rs.EOF
.AddItem rs.Fields(0) & "" rs.MoveNext
Wend
End With
End If rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
加入我的数据库后,出现实时错误"94" 无效使用NULL,怎么改一下
CALL Command1_Click()
CALL Command1_Click()不是这条语句,我的意思是刚开始显示窗体时,数据库的全部记录显示在表格中,点查询刚在显示查询记录,你现在是显示窗体时记录为空
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSql As String
Dim i As Integer
Dim j As Integer cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\油装置检定数据库.mdb;Persist Security Info=False" strSql = ""
strSql = strSql & " select * " & vbNewLine
strSql = strSql & " from 信息表 " & vbNewLine
strSql = strSql & " where 1=1 " & vbNewLine
If Text1.Text <> "" Then
strSql = strSql & " and 记录编号 = '" & Trim(Text1.Text) & "' " & vbNewLine
End If If Text2.Text <> "" Then
strSql = strSql & " and 送检单位 = '" & Trim(Text2.Text) & "' " & vbNewLine
End If If Combo1.Text <> "" Then
strSql = strSql & " and 流量计名称 = '" & Trim(Combo1.Text) & "' " & vbNewLine
End If
rs.Open strSql, cn, adOpenStatic, adLockOptimistic With MSFlexGrid1
.Rows = 1
.Cols = 1
If rs.RecordCount > 0 Then
.Cols = rs.Fields.Count + 1
.Rows = rs.RecordCount + 1 While Not rs.EOF
i = i + 1
For j = 1 To .Cols - 1
.TextMatrix(i, j) = rs.Fields(j - 1) & ""
Next j rs.MoveNext
Wend
Else
MsgBox "没有数据"
End If
End With rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End SubPrivate Sub Form_Load()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Combo1.Clear
Call MSFlexGrid1def
' Call Command1_Click
cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\油装置检定数据库.mdb;Persist Security Info=False" rs.Open "select 流量计名称 from 信息表 group by 流量计名称", cn, adOpenStatic, adLockOptimistic If rs.RecordCount > 0 Then
With Combo1
.AddItem ""
While Not rs.EOF
.AddItem rs.Fields(0) & "" rs.MoveNext
Wend
End With
End If rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
Private Sub MSFlexGrid1def() '将list2的表头初始化 入库
MSFlexGrid1.TextMatrix(0, 0) = "品名"
MSFlexGrid1.TextMatrix(0, 1) = "规格"
MSFlexGrid1.TextMatrix(0, 2) = "数量"
MSFlexGrid1.TextMatrix(0, 3) = "单位"
MSFlexGrid1.TextMatrix(0, 4) = "单价(元)"
MSFlexGrid1.TextMatrix(0, 5) = "总额(元)"
MSFlexGrid1.TextMatrix(0, 6) = "入库日期"
MSFlexGrid1.TextMatrix(0, 7) = "入料人编号"
MSFlexGrid1.TextMatrix(0, 8) = "入料人"
MSFlexGrid1.TextMatrix(0, 9) = "经手人"
MSFlexGrid1.TextMatrix(0, 10) = "说明"
MSFlexGrid1.TextMatrix(0, 11) = "自动编号"
End Sub
品名下没有数据,一点查询别的字段没有显示,只有数据,刚开始显示窗体时,数据库的全部记录没有显示在表格中
在你的数据库中有吗?email发过来吧