Solved

binding data to datagrid control in visual basic 6.0

Posted on 2006-06-11
14
405 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, left to enroll

615 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