关于vb DataGrid 的问题,请高手指教!!!
我想做一个数据库(数据库为access)的查询系统,我用DataGrid控件来显示查询的数据, 我用Set DataGrid1.DataSource = Adodc1 Adodc1跟数据库绑定,为什么DataGrid1控件 一开始就显示access的数据,而且查询结果总是显示整个数据表而不是只显示查询结果,请哪个高手能告诉我为什么!?我已经困惑了一个星期了!我的源代码 Private Rs As Recordset Private Conn As Connection '查询按钮 Private Sub Command1_Click() Dim strSQL As String On Error GoTo Err strSQL = "Select * From Authors Where Au_ID=" & Trim(Text1.Text) & "" Set Rs = New Recordset Rs.Open strSQL, Conn, adOpenStatic, adLockBatchOptimistic Set Adodc1.Recordset = Rs Set DataGrid1.DataSource = Adodc1 DataGrid1.Refresh Set Rs = Nothing Exit Sub Err: MsgBox Err.Description Set Rs = Nothing End Sub '系统加载 Private Sub Form_Load() Set Conn = New Connection Conn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=D:\Documents and Settings\Administrator\My Documents\BIBLIO.MDB" Set Rs = New Recordset Rs.CursorLocation = adUseClient Rs.Open "authors", Conn, adOpenStatic, adLockBatchOptimistic Set Adodc1.Recordset = Rs Set Rs = Nothing End Sub 加载时把 Rs.Open "authors", Conn, adOpenStatic, adLockBatchOptimistic Set Adodc1.Recordset = Rs Set Rs = Nothing 去掉就可以解决dbgrid 还是一开始就显示整个表?如何去掉啊? |