vb 查询数据库多字段
DimmyconAsNewADODB.ConnectionDimmyrsAsNewADODB.RecordsetDimcnAsNewADODB.ConnectionDim...
Dim mycon As New ADODB.Connection
Dim myrs As New ADODB.Recordset
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
'选择产品名称
If Combo1.Text = Combo1.List(1) Then
SQL = "select * from newkai where Machine1 =2号机 or Machine2 =2号机 or Machine3 =2号机 or Machine4 =2号机 or Machine5 =2号机 ":
rs.Open SQL, cn, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = rs
DataGrid1.Refresh
'DataGrid1列宽设置
DataGrid1.Columns(0).Width = 950
DataGrid1.Columns(1).Width = 1500
DataGrid1.Columns(2).Width = 950
DataGrid1.Columns(3).Width = 2000
DataGrid1.Columns(4).Width = 950
DataGrid1.Columns(5).Width = 950
DataGrid1.Columns(6).Width = 950
DataGrid1.Columns(7).Width = 950
DataGrid1.Columns(8).Width = 950
DataGrid1.Columns(9).Width = 950
DataGrid1.Columns(10).Width = 950
DataGrid1.Columns(11).Width = 950
DataGrid1.Columns(12).Width = 950
DataGrid1.Columns(13).Width = 950
End If
'重新查询清除前段查询数据
Set rs = Nothing
End Sub
Private Sub Form_Load()
'DataGrid1显示数据库
mycon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database\obese.mdb;Persist Security Info=False"
mycon.CursorLocation = adUseClient
mycon.Open
myrs.Open "select * from query", mycon, 3, 3
Set DataGrid1.DataSource = myrs
DataGrid1.Refresh
'DataGrid1列宽设置
DataGrid1.Columns(0).Width = 950
DataGrid1.Columns(1).Width = 1500
DataGrid1.Columns(2).Width = 950
DataGrid1.Columns(3).Width = 2000
DataGrid1.Columns(4).Width = 950
DataGrid1.Columns(5).Width = 950
DataGrid1.Columns(6).Width = 950
DataGrid1.Columns(7).Width = 950
DataGrid1.Columns(8).Width = 950
DataGrid1.Columns(9).Width = 950
DataGrid1.Columns(10).Width = 950
DataGrid1.Columns(11).Width = 950
DataGrid1.Columns(12).Width = 950
DataGrid1.Columns(13).Width = 950
'查询连接数据库
cn.ConnectionString = "provider=Microsoft.jet.OLEDB.4.0;" & _
"Persist security info= False; Data source=" & App.Path & "\Database\obese.mdb"
cn.Open
cn.CursorLocation = adUseClient
'Combo1值设置
Combo1.AddItem "", 0
Combo1.AddItem "2号机", 1
End Sub
语法错误??
该怎么改 展开
Dim myrs As New ADODB.Recordset
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
'选择产品名称
If Combo1.Text = Combo1.List(1) Then
SQL = "select * from newkai where Machine1 =2号机 or Machine2 =2号机 or Machine3 =2号机 or Machine4 =2号机 or Machine5 =2号机 ":
rs.Open SQL, cn, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = rs
DataGrid1.Refresh
'DataGrid1列宽设置
DataGrid1.Columns(0).Width = 950
DataGrid1.Columns(1).Width = 1500
DataGrid1.Columns(2).Width = 950
DataGrid1.Columns(3).Width = 2000
DataGrid1.Columns(4).Width = 950
DataGrid1.Columns(5).Width = 950
DataGrid1.Columns(6).Width = 950
DataGrid1.Columns(7).Width = 950
DataGrid1.Columns(8).Width = 950
DataGrid1.Columns(9).Width = 950
DataGrid1.Columns(10).Width = 950
DataGrid1.Columns(11).Width = 950
DataGrid1.Columns(12).Width = 950
DataGrid1.Columns(13).Width = 950
End If
'重新查询清除前段查询数据
Set rs = Nothing
End Sub
Private Sub Form_Load()
'DataGrid1显示数据库
mycon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database\obese.mdb;Persist Security Info=False"
mycon.CursorLocation = adUseClient
mycon.Open
myrs.Open "select * from query", mycon, 3, 3
Set DataGrid1.DataSource = myrs
DataGrid1.Refresh
'DataGrid1列宽设置
DataGrid1.Columns(0).Width = 950
DataGrid1.Columns(1).Width = 1500
DataGrid1.Columns(2).Width = 950
DataGrid1.Columns(3).Width = 2000
DataGrid1.Columns(4).Width = 950
DataGrid1.Columns(5).Width = 950
DataGrid1.Columns(6).Width = 950
DataGrid1.Columns(7).Width = 950
DataGrid1.Columns(8).Width = 950
DataGrid1.Columns(9).Width = 950
DataGrid1.Columns(10).Width = 950
DataGrid1.Columns(11).Width = 950
DataGrid1.Columns(12).Width = 950
DataGrid1.Columns(13).Width = 950
'查询连接数据库
cn.ConnectionString = "provider=Microsoft.jet.OLEDB.4.0;" & _
"Persist security info= False; Data source=" & App.Path & "\Database\obese.mdb"
cn.Open
cn.CursorLocation = adUseClient
'Combo1值设置
Combo1.AddItem "", 0
Combo1.AddItem "2号机", 1
End Sub
语法错误??
该怎么改 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询