I have a datagrid problem. It is my first time working with ADO. This is supposed to be an easy app. I have a text box to input a number. The datagrid is supposed to display the search result. I have a form, with a text box, a search button and a datagrid.
I have the following code on the click event:
--------------
Private Sub cmdSearch_Click()
Dim strSQL As String
Dim rsResult As New Recordset
Dim cnDB As New Connection
strSQL = "SELECT Store, Name, Articlename, InStock" _
& "FROM StockItem" _
& "Where ArticleNo = " & txtArticleNo.Text
cnDB.ConnectionString= _
"Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\StockItem.mdb"
cnDB.Open
Set rsResult = Nothing
rsResult.Open strSQL, cnLagerHK, adOpenStatic, adLockOptimistic
Set Datagrid1.DataSource = rsResult
cnDB.Close
End Sub
-------
I know the rsResult is filled with the right result from the query (it showed in a message box). According to the books/articles/code I've read, this should work. There are no error messages. I have tried Clearfields and refresh, but the grid remains empty (standard 2 columns 1 row).
I am using VB 6.0 (SP5) on a Win2K server. I developed the DB in Access 2K.
Hope you can help.
Thanks.
I have the following code on the click event:
--------------
Private Sub cmdSearch_Click()
Dim strSQL As String
Dim rsResult As New Recordset
Dim cnDB As New Connection
strSQL = "SELECT Store, Name, Articlename, InStock" _
& "FROM StockItem" _
& "Where ArticleNo = " & txtArticleNo.Text
cnDB.ConnectionString= _
"Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\StockItem.mdb"
cnDB.Open
Set rsResult = Nothing
rsResult.Open strSQL, cnLagerHK, adOpenStatic, adLockOptimistic
Set Datagrid1.DataSource = rsResult
cnDB.Close
End Sub
-------
I know the rsResult is filled with the right result from the query (it showed in a message box). According to the books/articles/code I've read, this should work. There are no error messages. I have tried Clearfields and refresh, but the grid remains empty (standard 2 columns 1 row).
I am using VB 6.0 (SP5) on a Win2K server. I developed the DB in Access 2K.
Hope you can help.
Thanks.