answersLogoWhite

0


Best Answer

It depends on what version of VB you are using, and what version of SQL Server you're attempting to connect to. Also, there are several ways to connect from each version of VB to each version of SQL Server (ODBC, ADODB, DSN-less, etc.). Since your question does not provide enough specifics to answer adequately, I refer you to the "Connection Strings" link at the bottom of this page (or you may just type in www.connectionstrings.com in your browser).

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

There are plenty of ways you can do this. The 2 most common would be a Data Control, which will give you a record navigator just like in access, you can bind this to a Data Bound List, Grid or Combo Box to display it.

The other way would be to use ADO directly in VB code. Both are pretty similar, and theres only a couple of steps to connect it all up.

To use the Data control, First Create a new VB6 project and goto the Project -> Components menu. In here check the item "Microsoft Data Bound Grid Control 5.0" and click OK.

Now you can drag out both the "Data" control, and the "Data Bound Grid". On your new Data1 control, you can set the path to your access database and what table or query you want to use. Then you can select your DBGrid1 control and set it's "Data Source" to "Data1".

This is fine for something basic, but anything more advanced you're going to want to use code.

First step, go to www.connectionstrings.com and make a connection string for your database. This is where you select what type of database you're using (in this case, Access), and where you set your database password, file location and advanced options.

Now, Create a new VB6 project and goto the Project -> References menu. In here find and check the "Microsoft ActiveX Data Objects 2.6" library.

Now double click on the form to get to the Form_Load event, and add the following.

Dim oCon as New ADODB.Connection

Dim oRs as New ADODB.Recordset

oCon.Open "Connection String"

oRs.Open "SELECT * FROM TABLE", oCon, adOpenKeyset, adLockOptimistic

Now you can use the data from the query "SELECT * FROM TABLE" in code. Use oRs!FieldName to access each field's value, and use the oRs.MoveNext, .MovePrevious, .MoveFirst & .MoveLast functions to navigate around.

Eg

' Connect to the database in the same folder as the application

oCon.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & App.Path & "\Data.mdb;Uid=Admin;Pwd=;"

' Grab only the fields & data we need to work with.

oRs.Open "SELECT Name, Price, Views FROM Products WHERE Stock > 0", oCon, adOpenKeyset, adLockOptimistic

' Loop until we get to the end of the table

Do Until oRs.EOF

' $5.00 - Chips

List1.AddItem "$" & Format(oRs!Price, "###0.00") & " - " & oRs!Name

' Add 1 to this items "views" counter

oRs!Views = oRs!Views + 1

' Move to the next record

oRs.MoveNext ' Move to the next record

Loop

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

You can connect visual basic to an xampp as its database by accessing the main control panel of the system and rerouting the entire flow to accomodate a usb connection.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you connect Visual Basic with SQL server database?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you connect vb with sql server?

search for this line below there is a video you can watch" VB.NET Database Tutorial - Connecting To Microsoft SQL Server (PART 1) (Visual Basic .NET) Thank you Dariush from Wickenburgnet.com


I made a database using xampp at localhost phpmyadmin i made a form in visual basic and i want it to connect to my database do you know how to do it?

no, I don't


What are the basic feture of foxpro?

Basic feature of Microsoft Visual FoxPro is same with other programming language. You can develop a program either local database or coming from a SQL Server. Aside from that you can customize same with Visual Basic.


What has the author Dan Rahmel written?

Dan Rahmel has written: 'Visual Basic' -- subject(s): BASIC (Computer program language), Microsoft Visual BASIC 'Visual Basic.NET programmer's reference' -- subject(s): BASIC (Computer program language), Microsoft Visual BASIC, Microsoft .NET 'Sams teach yourself database programming with Visual Basic 6 in 24 hours' -- subject(s): Database design, Microsoft Visual Basic for Windows, BASIC (Computer program language) 'Building Web database applications with Visual Studio 6' -- subject(s): Application software, Database design, Development, Microsoft Visual studio, Web databases 'Server Scripts With Visual Javascript (Hands-on Web Development)' 'Nuts and bolts filmmaking' -- subject(s): Motion pictures, Cinematography, Production and direction


How do you connect visual basic 6.0 access database using module and data environment?

There are several ways to connect Visual Basic 6.0 access databases, but to use module and data environment equipment, one must obtain access to the actual program to download first.


What does ODBCstands for in visual basic?

Open Database Connectivity.


How do you store photos in a database using visual basic?

You cannot store images inside a database, you can store information about where the image is kept in a database. -Peter


Does 70-640 require programming skills in visual basic?

No - that is a Server exam.


What is difference java and visual basic programming?

java is a server side programing where as visual basic is a client side programing(This programing Language is different from oops)


How Can you use MS Visual Basic 2005 Express as a direct database application?

YES


How do you create a save button to save a dataset into a database in Visual Basic?

i love pie


What is the difference between oracle and visual basic which one is the best suited for backup database system?

Oracle is a RDBMS software, means, Oracle holds the database (data created/updated using application). Visual basic is tool to develop applications & this is from Microsoft. You can write programs/application to access the data from the RDBMS like Oracle, Microsoft SQL Server, etc. Since the functionality differs (i.e. Oracle = RDBMS & Visual basic =Application development Tool) for the two software applications, "which one is the best" can not be answered.