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
Solved

binding data to datagrid control in visual basic 6.0

Posted on 2006-06-11
14
382 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

860 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