注册 登录
编程论坛 VB6论坛

vb中的排列程序

紫露 发布于 2013-04-03 08:56, 465 次点击
如下,我在"图号"中输入"WS1000002",点击"查询"表格中就只会出现所有的"WS1000002",,这个程序怎么编写(表格中的内容是从2个不同的表中搜索出来的)
只有本站会员才能查看附件,请 登录

Dim cn As Connection
Dim rs As adodb.Recordset
Dim rstemp As Recordset
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Command2_Click()
Dim FileName As String
FileName = "W:\设计更改单"
ShellExecute Me.hwnd, vbNullString, FileName, vbNullString, vbNullString, 1
End Sub
Private Sub Command1_Click()
sql = "drawingnumber='" & Trim(Text1.Text) & "'"
Call insearch(sql)
End Sub
Private Sub Form_Load()
sql = ""
Call insearch(sql)
Call loadWSPdrawing
End Sub
Private Sub insearch(ByVal sql As String)
  Set cn = New Connection
  cn.CursorLocation = adUseClient
  cn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\jxc.mdb;"
Set rs = New adodb.Recordset
rs.LockType = adLockOptimistic
If Len(Trim(sql)) <= 0 Then
   rs.Open "select * from instore union select * from WSPdrawing", cn, adOpenDynamic
Else
   rs.Open "select * from instore union select * from WSPdrawing where " & Trim(sql), cn, adOpenDynamic
End If
   Set DataGrid1.DataSource = rs
End Sub
Private Sub loadWSPdrawing()
   Set rstemp = New Recordset
   rstemp.Open "select * from WSPdrawing", cn, adOpenForwardOnly, adLockReadOnly
   If rstemp.RecordCount > 0 Then
      rstemp.MoveFirst
      Do While Not rstemp.EOF
      Text1.Text = rstemp.Fields("drawingnumber")
      Text2.Text = rstemp.Fields("description")
         rstemp.MoveNext
         If rstemp.EOF Then
         End If
      Loop
   End If
End Sub

3 回复
#2
Artless2013-04-03 17:30
数据结构?
#3
风吹过b2013-04-03 19:09
rs.Open "select * from instore union select * from WSPdrawing", cn, adOpenDynamic
Else
   rs.Open "select * from instore union select * from WSPdrawing where " & Trim(sql), cn, adOpenDynamic

增加查询的条件。自己去看一下 SQL 命令 吧。
多表查询,比较烦。
#4
紫露2013-04-08 14:12
回复 3楼 风吹过b
看 了,也不知道错在哪 里,还请帮个忙,帮我看看
1