Welcome to Dream.In.Code
Become a VB Expert!

Join 137,198 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,339 people online right now. Registration is fast and FREE... Join Now!




Setting DataGrid DataSource and DataPropetie

 
Reply to this topicStart new topic

Setting DataGrid DataSource and DataPropetie, Setting Datasource in Runtime

blee
13 Jun, 2008 - 11:51 PM
Post #1

New D.I.C Head
*

Joined: 1 Jun, 2008
Posts: 8

Hi

I would like to set data grids Datamember and Datasource.
Here is my Code , but my grid stays empty with no errors.

What Iam I doing wrong ?

CODE

' Refresh DataGrid View
  Dim Cnxn2 As ADODB.Connection
    Dim adoRecSetA As ADODB.Recordset
    
      set dgOrder.DataSource = Cnxn2
   '  dgOrder.DataMember = "adoRecSet"
    
    ' Open a connection using the Microsoft Jet provider
'    Set Cnxn3 = New ADODB.Connection
'    Cnxn2.Provider = "Microsoft.Jet.OLEDB.4.0"
'    Cnxn2.Open "C:\Protogen.mdb"
'
'    Set adoRecSetA = New ADODB.Recordset
'    adoRecSet.Open
'
'    strSQL = "SELECT * FROM Orderreference "
'
'    adoRecSet.Open , Cnxn2, adOpenDynamic, adLockOptimistic, -1
'
'    dgOrder.Refresh


' Refresh DataGrid View
dgOrder.Visible = True
Set dgOrder.DataSource = Nothing
dgOrder.Refresh

Set dgOrder.DataSource = Cnx2n
frmCreateOrder.Refresh

User is offlineProfile CardPM
+Quote Post

mensahero
RE: Setting DataGrid DataSource And DataPropetie
14 Jun, 2008 - 12:23 AM
Post #2

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions
QUOTE

Dim adoRecSetA As ADODB.Recordset


is different from

QUOTE

adoRecSet.Open //no 'A'


and

QUOTE

dgOrder.DataSource = Cnx2n


IMO .. i think it should be pointed into a recordset.. .DataSource = adoRecSetA ...

well not sure though.. blink.gif

This post has been edited by mensahero: 14 Jun, 2008 - 12:24 AM
User is offlineProfile CardPM
+Quote Post

blee
RE: Setting DataGrid DataSource And DataPropetie
14 Jun, 2008 - 01:49 AM
Post #3

New D.I.C Head
*

Joined: 1 Jun, 2008
Posts: 8

QUOTE(mensahero @ 14 Jun, 2008 - 01:23 AM) *

QUOTE

Dim adoRecSetA As ADODB.Recordset


is different from

QUOTE

adoRecSet.Open //no 'A'


and

QUOTE

dgOrder.DataSource = Cnx2n


IMO .. i think it should be pointed into a recordset.. .DataSource = adoRecSetA ...

well not sure though.. blink.gif


I have change to adoRecSetA
No was not the problem !!!

User is offlineProfile CardPM
+Quote Post

tope10
RE: Setting DataGrid DataSource And DataPropetie
25 Jul, 2008 - 01:38 AM
Post #4

New D.I.C Head
*

Joined: 25 Jun, 2008
Posts: 22



Thanked: 2 times
My Contributions
QUOTE(blee @ 14 Jun, 2008 - 12:51 AM) *

Hi

I would like to set data grids Datamember and Datasource.
Here is my Code , but my grid stays empty with no errors.

What Iam I doing wrong ?

CODE

' Refresh DataGrid View
  Dim Cnxn2 As ADODB.Connection
    Dim adoRecSetA As ADODB.Recordset
    
      set dgOrder.DataSource = Cnxn2
   '  dgOrder.DataMember = "adoRecSet"
    
    ' Open a connection using the Microsoft Jet provider
'    Set Cnxn3 = New ADODB.Connection
'    Cnxn2.Provider = "Microsoft.Jet.OLEDB.4.0"
'    Cnxn2.Open "C:\Protogen.mdb"
'
'    Set adoRecSetA = New ADODB.Recordset
'    adoRecSet.Open
'
'    strSQL = "SELECT * FROM Orderreference "
'
'    adoRecSet.Open , Cnxn2, adOpenDynamic, adLockOptimistic, -1
'
'    dgOrder.Refresh


' Refresh DataGrid View
dgOrder.Visible = True
Set dgOrder.DataSource = Nothing
dgOrder.Refresh

Set dgOrder.DataSource = Cnx2n
frmCreateOrder.Refresh




' Refresh DataGrid View
Dim Cnxn2 As ADODB.Connection
Dim adoRecSetA As ADODB.Recordset

' Open a connection using the Microsoft Jet provider
Set Cnxn2 = New ADODB.Connection
Cnxn2.Provider = "Microsoft.Jet.OLEDB.4.0"
Cnxn2.Open "C:\Protogen.mdb"
'
Set adoRecSetA = New ADODB.Recordset

strSQL = "SELECT * FROM Orderreference "

adoRecSet.Open strSQL, Cnxn2, adOpenDynamic, adLockOptimistic, -1


' Refresh DataGrid View

Set dgOrder.DataSource = Cnx2n

' i already corrected the code. please check it.

the logic in database connectivity is you have to create first a connection the will open the database, then create a recordset that will open up the table using sql command or the name of query or table and then you use a datagrid as a container of the result of the recordset.



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 12:13PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month