How to open and edit SQL database with VB6

Hello Experts.
I need to open and edit an SQL database using VB6.
Please show me how to start.
Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
that is a big/vaste question...

what database exactly?
what do you mean by "edit"?
SvenTech Lead Web-DevelopmentCommented:
Maybe this will help:

And here you will find some mor connction string examples:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HESUSAuthor Commented:

The Database I need to edit is "*.Sql".
EDIT is to be able to read and write to the Database.

DarthSonic , Thanks I am going to check it now.
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Here is an example for you.
    Dim conSQLServerDatabase As New ADODB.Connection
    Dim RS As New ADODB.Recordset
    'conSQLServerDatabase = Server Name, Database Name, Windows Authentication
    conSQLServerDatabase.connectionstring = "Server=MyServer;Database=DatabaseName;Integrated Security=yes"
    'Opens the Connection
    With RS
        .open "INSERT Into YouTableGoesHere(Name, Status) VALUES('John', 'A')", conSQLServerDatabase, adOpenDynamic, adLockOptimistic
        .open "UPDATE YouTableGoesHere SET Status = 'B' Where Name = 'John'", conSQLServerDatabase, adOpenDynamic, adLockOptimistic
        .open "DELETE FROM YouTableGoesHere WHERE Status ='B'", conSQLServerDatabase, adOpenDynamic, adLockOptimistic
        .open "SELECT * FROM YouTableGoesHere WHERE Status = 'B'", conSQLServerDatabase, adOpenDynamic, adLockOptimistic
    End With
End Sub

Open in new window

When you add, edit, remove data from your database you will normally do it by executing SQL commands.  Normally a RecordSet is what you will be working with.  You will send a request to the database and you will receive a collection of records that fall within the paramaters of what you specify.  This is your RecordSet.

When you see * you are asking for everything.
Select * From Customer (Asks for every field in the Customer Table)
Select LastName, FirstName, Status, City From Customer (Asks for only LastName, FirstName... from Customer Table.  If there are more fields in the database you will not see them in your RecordSet).

You can also specify a range.
Select * From Customer Wher LastName = "Smith" (Will give you a RecordSet containing every field of the table and a record for how ever many people in the table with a  Last Name of Smith).

After you have a connection to your database, send a request for data (SQL Statement), and receive an answer (RecordSet) it is up to you to do whatever you want with the data.

If you want a RecordCount you will need to execute two commands: rs.MoveLast and rs.MoveFirst rs is the reference to your RecordSet.  After you do that you can urse rs.RecordCount to know how many records fell within your criteria.

If you want to populate something or do something with each record normally people will create a loop:
Do while Not rs.EOF
    textbox1.text = textbox1.text & Trim(rs!Last) & vbCRLF

EOF is the End Of File marker.  When you reach this record you know that you are at the end of the database.  If the recordset only contains one record EOF, the do loop is skipped because there are no records.

There are different ways to Open the database (Dynaset, Static etc...) that will put your recordset in different modes.  ReadOnlly is faster but you can't update.  Read/Write will let you update but could be a little slower.

When you open your connection you can also specify if you want network locking of the data which is used when you have multiple users accessing the same database.


I found a website with more detailed information:
HESUSAuthor Commented:
Many thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.