如何让DATAGIRD中显示我想要的几列数据?
如题所示。
这是我在DATAGIRD中显示数据的代码。把全部数据都显示了,但是我只需要几列数据,应该怎么改下?
Private Sub Command1_Click()
Dim strSQL As String
Dim strCon(4) As String
Dim intCount As Integer
Dim i As Integer
intCount = 0
'获得所有得查询条件
If Text1.Text <> "" Then
If Check1.Value = 1 Then
strCon(1) = "船型 like '%" & Text1.Text & "%'"
Else
strCon(1) = "船型='" & Text1.Text & "'"
End If
Else
strCon(1) = ""
End If
If Text2.Text <> "" Then
If Check1.Value = 1 Then
strCon(2) = "产品号 like '%" & Text2.Text & "%'"
Else
strCon(2) = "产品号='" & Text2.Text & "'"
End If
Else
strCon(2) = ""
End If
If Text3.Text <> "" Then
If Check1.Value = 1 Then
strCon(3) = "图号 like '%" & Text3.Text & "%'"
Else
strCon(3) = "图号='" & Text3.Text & "'"
End If
Else
strCon(3) = ""
End If
If Text4.Text <> "" Then
If Check1.Value = 1 Then
strCon(3) = "零件号 like '%" & Text4.Text & "%'"
Else
strCon(3) = "零件号='" & Text4.Text & "'"
End If
Else
strCon(3) = ""
End If
If strCon(1) = "" And strCon(2) = "" And strCon(3) = "" And strCon(4) = "" Then
strSQL = "select * from xinxi"
Else
strSQL = "select * from xinxi where "
For i = 1 To 4
If strCon(i) <> "" Then
intCount = intCount + 1
If intCount = 1 Then
strSQL = strSQL + strCon(i)
Else
strSQL = strSQL + " and " + strCon(i)
End If
End If
Next
End If
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Persist Security Info=False"
Adodc1.CursorLocation = adUseClient
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = strSQL
Adodc1.Refresh
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim db As New ADODB.Connection
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Persist Security Info=False"
db.ConnectionString = Adodc1.ConnectionString
If db.State <> ADODB.ObjectStateEnum.adStateClosed Then db.Close
db.Open
End Sub
根据上面的查询条件,我只想要我想要几列数据,该如何搞