Solved

ADO

Posted on 1998-10-20
4
479 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

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

Suggested Solutions

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 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…

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

11 Experts available now in Live!

Get 1:1 Help Now