Solved

ADO

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

810 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