Solved

binding data to datagrid control in visual basic 6.0

Posted on 2006-06-11
14
365 Views
Last Modified: 2013-11-25
can anybody provide sample code of how to bind data to datagrid using visual basic 6.0. i am getting customers list from database and want to bind it to datagrid.

thanks,
sandeep
0
Comment
Question by:cognos79
  • 8
  • 2
14 Comments
 
LVL 8

Expert Comment

by:hiteshgupta1
ID: 16883218
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 16892005
if you are using microsoft access then here:
Option Explicit()
dim cn as ADODB.Connection
dim rs as Adodb.RecordSet
dim strDataBasePath


Private Sub Form Load()
`****Setting the connection*****

Set cn = new AdoDB.connection
Set rs = new Adodb.Recordset

`****specify the PAth

strDataBasePath = "c:\Nwind.mdb"

`******setting the provider to use

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=`" & strDataBasePath & "`"

`*** important****
cn.CursorLocation = adUseClient


rs.open "Select * From tblOwners", cn, adOpenKeySet, adLockOptimistic

`binding the control

Set DataGrid1.DataSource = rs

Datagrid1.refresh

End sub



0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 16892012
If you are using SQL Server then change the Provider...

goto www.connectionstring.com

for a list of connection strings...

I hope I help you

cheers
0
 
LVL 3

Author Comment

by:cognos79
ID: 16898745
hey jackofPH,

i am using this code..i did wht you said....there is no error but i dont see any data binded to the datagrid. its strange.

Dim objConn As New adodb.Connection
Dim objCmd As New adodb.Command
Dim objParm1 As New adodb.Parameter
Dim objRs As New Recordset
Dim strSQL

    objConn.Open "Provider=SQLOLEDB;User ID=xxx;Password=xxx;Initial Catalog=xxx;Server=xxxx;Connect Timeout=60;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=WEBTRACKER"

    ' Set CommandText equal to the stored procedure name.
    objCmd.CommandText = "getcustomeraddr"
    objCmd.CommandType = adCmdStoredProc
   
    strSQL = "SELECT first_name + char(13) + last_name as 'name' From customer where customer_id = 1"
   
    objRs.CursorLocation = adUseClient
    objRs.Open strSQL, objConn, adOpenKeyset, adLockOptimistic
    Set dgCustomers.DataSource = objRs
   
    dgCustomers.Refresh


    objRs.Close
    objConn.Close
    Set objRs = Nothing
    Set objConn = Nothing

any ideas,
sandeep
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 16899082
did you try executing your query in the SQL server? does it returns any records?..
strSQL = "SELECT first_name + char(13) + last_name as 'name' From customer where customer_id = 1"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:JackOfPH
ID: 16899094
change this code...

    objRs.CursorLocation = adUseClient
   
to this

objconn.Cursorlocation = adUseClient

it should be connectionstring not the recordset...
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 16899102
>>>>it should be connectionstring not the recordset...

sorry, it is connection not recordset...
0
 
LVL 3

Author Comment

by:cognos79
ID: 16907565
that didnt help me. i solved it like this.

  Dim db As Connection
  Set db = New Connection
  db.CursorLocation = adUseClient
  db.Open "Provider=SQLOLEDB;xxxxx"

  Set adoPrimaryRS = New Recordset
  adoPrimaryRS.Open "select customer from customer", db, adOpenStatic, adLockOptimistic

  Set dgCustomers.DataSource = adoPrimaryRS



can you guys tell me how can i put a radiobutton column in datagrid. for all the rows in datagrid
a radiobutton column has to be added. i want the user to select one radiobutton in the grid on submit button and i want to grab the value of the record he selected. (validation should happen to make sure he selected only one record).

i need to do this ASAP. help me

how to do this.
0
 
LVL 15

Accepted Solution

by:
JackOfPH earned 250 total points
ID: 16908175
you mat need to use a commercial grid for that... WHY? becauase datagrid has lack of functionality on what you are aiming for...
have alook... here

http://www.drdelphi.com/orderform.html#bennet-tec

http://www.fpoint.com

1.Ultimate Grid 97 ActiveX (probably the one that we will buy, LOTS of features) at www.dundas.com.
2.GridWiz at www.mcraesoft.com.
3.Objective Grid CCE at www.stingsoft.com

There are also the ones without source code by apex (www.apexsc.com), XGrid at www.green-tree.com, spread 2.5 (a very good one, too) at www.fpoint.com, dbcomplete at www.visualcomp.com, Data widgets 2.0 at www.shersoft.com.



0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 16908184
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 16908187
use the true dbgrid...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now