Solved

ADO

Posted on 1998-10-20
4
478 Views
Last Modified: 2013-12-25
how do i use ADO in VB to access SQL Server?

i'm using ADO version 2.0, SQL SERVER 6.5, VB 5.0.
0
Comment
Question by:ireeny
  • 3
4 Comments
 

Accepted Solution

by:
narula earned 10 total points
ID: 1497100
First, make sure that you've installed the latest Data Access Components (http://www.microsoft.com/data).  Also, be aware that you will not be able to directly use SQL Server as an OLEDB data source.  You will have to use the OLEDB to ODBC provider or more likely you will use ODBC directly.  In any event, make sure you have an ODBC System DSN created for your SQL database.

In VB, make sure that there's a project reference to the ADO 2.0 library.  Be warned that there's no direct binding of controls here.  You'll have to do all of this manually by coding your bindings (or upgrade to VB6).  Now, assuming your using a standard form:
' In general declarations
Dim conn as ADODB.Connection

' In the Form_Load event procedure
  conn.open ConnectionString,UserID,Password
' and so on

It's as simple to use as under ASP.  If you're looking for a more RAD approach, goto the Microsoft Online Member Downloads page and download the from ISG Data Control which works with ADO Recordsets. :-)

0
 

Author Comment

by:ireeny
ID: 1497101
great ! that worked.

however, i can't seem to retrieve data into a DBGRID.
how do i overcome this ?

(if you help me with this, i'll increase points to 20 ! thanks )
0
 

Expert Comment

by:narula
ID: 1497102
Let me correct this by saying that if you download the latest Data Access, you should have the ability to use the SQL OLEDB provider.  I'd forgotten that it was included recently.
0
 

Expert Comment

by:narula
ID: 1497103
Well...I'm not going to sit here and write the code for you, but I will give you some idea - since the VB5 grid doesn't bind to ADO (unless you use the free ISGData Control for ADO *hint*).

First, grab your recordset and with the fields collection, add a corresponding column to the DBGrid's Columns collection, setting the Visible and Caption properties.  Then set the AllowAddNew property to True and for each record in your recordset by using the Bookmark property and the columns collection of the DBGrid, and incrementally add values into each cell of that DBGrid row.  When you reach the end of each row, move to the next row and repeat the last step until you've reached the end of the recordset.

As I said before, this is the unbound way - and it's time consuming.  Now, after you've updated the grid, you'll have to save changes by evaluating each row and saving it's values.  Do yourself a favor and download the ISGData Control for ADO at: http://premium.microsoft.com/msdn/downloads/isgdata/default.htm

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

747 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

16 Experts available now in Live!

Get 1:1 Help Now