Avatar of smile34
smile34

asked on 

data grid + ADO recordset

Hi..

I try to connect a data grid (MS Data Grid Control 6.0 (oledb)) with ADO recordset.

Below is the source code :
-------------------------------
Private Sub Form_Load()
  Dim objConn As ADODB.Connection
  Dim objComm As ADODB.Command
  Dim objRec As ADODB.Recordset
  Dim strcon As String
  Dim varBkmark
 
  'Create and open the Connection object
  Set objConn = New ADODB.Connection
  strconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Program Files\Microsoft Visual Studio\VB98\data.mdb; Persist Security Info=False"
  objConn.ConnectionString = strconn
  objConn.Open
 
  'Create and set the Command object
  Set objComm = New ADODB.Command
  objComm.ActiveConnection = objConn
  objComm.CommandText = "Stock"
  objComm.CommandType = adCmdTable
 
  'Create and set the Recordset object
  Set objRec = New ADODB.Recordset
  Set objRec.Source = objComm
  objRec.CursorType = adOpenKeyset
  objRec.Open
 
  Set DataGrid1.DataSource = objRec
  DataGrid1.Refresh
End Sub
-----------------
Ques : why i did'nt see anything on the datagrid? what's wrong with the code?

note :
1. i didn't receive any error message
2. the database & table is fine, because i can get the expected result if i use ADODC(data control) component instead of using ADO coding.

thanks in advance...
Visual Basic Classic

Avatar of undefined
Last Comment
smile34
Avatar of ivanc
ivanc

Smile34

Try objrec.refresh after the objrec.open
Hope this helps

Ivanc
Avatar of ivanc
ivanc

Rkeliher

However, you need to add all the reference for Outlook and Access to your project
Ivanc
Avatar of pinshah
pinshah

mAKE

objRec.CursorLocation = adUseClient


ASKER CERTIFIED SOLUTION
Avatar of pinshah
pinshah

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of pinshah
pinshah

Private Sub Form_Load()
  Dim objConn As ADODB.Connection
  Dim objRec As ADODB.Recordset
  Dim strcon As String
   
  'Create and open the Connection object
  Set objConn = New ADODB.Connection
  strconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Program Files\Microsoft Visual Studio\VB98\biblio.mdb; Persist Security Info=False"
  objConn.ConnectionString = strconn
  objConn.Open
   
  'Create and set the Recordset object
  Set objRec = New ADODB.Recordset
  Set objRec.ActiveConnection = objConn
  objRec.Source = "Select * From Authors"
 
  objRec.CursorType = adOpenKeyset
  'if u comment the line below u would not see records in the grid as by default the cursor location is server side.
  objRec.CursorLocation = adUseClient
  objRec.Open
   
  Set DataGrid1.DataSource = objRec
  DataGrid1.Refresh
End Sub
Avatar of smile34
smile34

ASKER

ivanc,

why i can't find refresh method for my objrec??

i've include the MS ADO library.. is'nt that enough?
Avatar of smile34
smile34

ASKER

Answer accepted
Avatar of smile34
smile34

ASKER

Thanks a lot for you guysss
Visual Basic Classic
Visual Basic Classic

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.

165K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo