Skip to main content
GameDev.net gamedev.net
🔒 Locked

Vb6 databases

Started by BloodLust666 Jul 10, 2006 at 3:23 PM 1 replies 600+ views
Original Post
BloodLust666
BloodLust666
I'm using VB6 and microsoft access databases. What i'm trying to do is somehow open the database file in VB and read and write to the fields. how would i go about doing that?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
smr
smr
You need to learn about ADO (ActiveX Data Objects) and SQL (Structured Query Language). Here's a quick run-down:

' Opening a connection to an Access Database:Dim cn As ADODB.ConnectionSet cn = New ADODB.Connection' www.connectionstrings.com has examples of all the connection strings you could ever want.' Notice \somepath\mydb.mdb - replace that with your actual database file and pathcn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=admin;Password=;"' Reading data. I'm assuming there is a table called "users" with two fields called "name" and "phone"Dim rs As ADODB.Recordset' This is SQL. It is asking for the name and phone fields of every record in the users tableSet rs = cn.Execute("SELECT [name], [phone] FROM [users];")While Not rs.Eof    Debug.Print "Name", rs("name")    Debug.Print "Phone", rs("phone")    ' Make sure you always movenext within loops. I've killed countless webservers by forgetting this one line    rs.MoveNextWendrs.Close' Inserting datacon.Execute "INSERT INTO [users] ([name],[phone]) VALUES('PATRICK', '555-555-5555')"' Changing datacon.Execute "UPDATE [users] SET [phone]='123-123-1234' WHERE [name]='PATRICK';"' Make sure you clean up after yourself!con.Close

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.