Solved

ADO

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

829 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