vs2008 中用vb语言adodb 怎样把搜索数据库的结果显示在datagridview中?求大神指点!!
展开全部
Private Sub Command1_Click()
sql = "'" & Trim(Text1.Text) & "'"
Call 表(sql)
End Sub
Private Sub 表(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;Persist Security Info=False;Jet OLEDB:Database Password=123"
Set rs = New ADODB.Recordset
rs.LockType = adLockOptimistic
If Len(Trim(sql)) <= 0 Then
rs.Open "select * from 表 ", Cn, adOpenDynamic
Else
rs.Open "select * from 表 where 表.图号=" & sql, Cn, adOpenDynamic
End If
Set DataGrid1.DataSource = rs
End Sub
这是我以前的,不过不是2008的,你看看
sql = "'" & Trim(Text1.Text) & "'"
Call 表(sql)
End Sub
Private Sub 表(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;Persist Security Info=False;Jet OLEDB:Database Password=123"
Set rs = New ADODB.Recordset
rs.LockType = adLockOptimistic
If Len(Trim(sql)) <= 0 Then
rs.Open "select * from 表 ", Cn, adOpenDynamic
Else
rs.Open "select * from 表 where 表.图号=" & sql, Cn, adOpenDynamic
End If
Set DataGrid1.DataSource = rs
End Sub
这是我以前的,不过不是2008的,你看看
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询