Solved

binding data to datagrid control in visual basic 6.0

Posted on 2006-06-11
14
395 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
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…

752 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