944,181 Members | Top Members by Rank

Ad:
Dec 6th, 2006
0

MDB2 SQL Connection

Expand Post »
Hi,

do anybody knows how to connect in sql mdb2 in Visual Basic 6

I only know how to connect in php...

this is my sample connection in php....

#======================================#

$mdb2 = connectdb();

$sql = "SELECT <fieldname> FROM <tablename>"

$results = selquery($sql,$mdb2);

closedb($mdb2);

#======================================#

do anyone knows how to do it in Visual Basic 6....


Please help me....
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
millanskie is offline Offline
63 posts
since Dec 2006
Dec 6th, 2006
0

Re: MDB2 SQL Connection

Hi,

Create a ODBC for the database say MyODBC

And use this Connection String

Dim AdoCn As New ADODB.Connection

AdoCn.ConnectionString = "Provider=MSDASQL.1;Password=MyPassword;Persist Security Info=True;User ID=MyUserID;Data Source=MyODBC"
AdoCn.Open


Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Dec 6th, 2006
0

Re: MDB2 SQL Connection

Thanks Veena for your answer I appreciate it very much... but can u give me a detailed code from opening a connection to closing a connection.... I'm really not good in database, I know this is too much.

Thanks anyway...
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
millanskie is offline Offline
63 posts
since Dec 2006
Dec 7th, 2006
0

Re: MDB2 SQL Connection

Hi,

Create a ODBC.
Add References to ur project "Microsoft ActiveX Data Objects 2.0 Library" (or any latest Version if u have)

In MDI Form Load :

Dim ad as ADODB.Connectionset ad=New ADODB.ConnectionLet ad.ConnectionString= "MyODBC;DSN=" & DatabaseName & ";UID=" & UserName & ";PWD=" & UserPasswordad.Open

To Get records from the Database use
dim ar as ADODB.recordsetset ar=new adodb.recordsetar.open "Select * From EmpMas Order By ENo"If Not (ar.EOF And ar.BOF) Thenar.MoveFirstdo while not ar.EOF Debug.Print ar("ENo") ar.movenextloopTo execute an SQL Statement :

ad.Execute "Update EmpMas Set EName ='MyName' Where ENo=1"

I Hope it is clear.

Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Dec 7th, 2006
0

Re: MDB2 SQL Connection

Sorry after posting i saw, it was not readable.

Create a ODBC.
Add References to ur project "Microsoft ActiveX Data Objects 2.0 Library" (or any latest Version if u have)

In MDI Form Load :

Dim ad as ADODB.Connection

set ad=New ADODB.Connection

Let ad.ConnectionString= "MyODBC;DSN=" & DatabaseName & ";UID=" & UserName & ";PWD=" & UserPassword

ad.Open


To Get records from the Database use

dim ar as ADODB.recordset

Set ar=new adodb.recordset

ar.open "Select * From EmpMas Order By ENo"

If Not (ar.EOF And ar.BOF) Then
ar.MoveFirst
do while not ar.EOF
Debug.Print ar("ENo")
ar.movenext
loop

End If

To execute an SQL Statement :

ad.Execute "Update EmpMas Set EName ='MyName' Where ENo=1"


I Hope it is clear.


Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Dec 7th, 2006
0

Re: MDB2 SQL Connection

Hi,

Thanks a lot Veena, your code is working great...

Thanks for the help.



Regards,
Millan
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
millanskie is offline Offline
63 posts
since Dec 2006
Dec 8th, 2006
0

Re: MDB2 SQL Connection

Hi,

Sorry I thought it was already running in sql connection, it was the other program using Microsoft Access is the one is running...

I'm still having a runtime error like this:

Runtime error '3709'

when I click debug it is pointing on
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. ar.Open "SELECT editorname FROM editormaster"


I dont know how to solve it.



Regards,
Millan
Last edited by millanskie; Dec 8th, 2006 at 5:29 am. Reason: edit the error msg
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
millanskie is offline Offline
63 posts
since Dec 2006
Dec 8th, 2006
0

Re: MDB2 SQL Connection

Hi,

Sorry, u have to give connection name also

ar.Open "SELECT editorname FROM editormaster", ad

Hope this will work

Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Dec 8th, 2006
0

Re: MDB2 SQL Connection

Hi Veena,

Thanks for the help, its really working now surely...


Thank You very much Veena.



Regards,
Millan
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
millanskie is offline Offline
63 posts
since Dec 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Call Fox Pro Program
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Is it possible to VB6 program download into 68HC11 microcontroller?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC