|
|
|
smartsoft (m)
|
Create a datasource name for your Access database
Set db = DBEngine.Workspaces(0).OpenDatabase("dbsourcename", ,"DSN=dbsourcename;UID=MyUID;PWD=Mypassw") ============================================================ This is for SQL SERVER.
You can do that in the same way it is done in VB6 or any other languages. Here is a quick sample:
NOTE: in Excel in your VB6 code editor go to Tools >> References and select MS ADO 2.x library before running this code
visual basic code:-------------------------------------------------------------------------------- Option Explicit
Dim adoConn As ADODB.Connection Dim strConString As String
Private Sub Worksheet_Activate() '================================ Dim adoRST As ADODB.Recordset Dim strSQL As String
strConString = "Provider=SQLOLEDB.1;Initial Catalog=smartsoft;" _ & "User ID=sa;Password=password;Persist Security Info=True"
Set adoConn = New ADODB.Connection adoConn.Open strConString Set adoRST = New ADODB.Recordset strSQL = "Select * from smartsoft" adoRST.Open strSQL, adoConn Do While Not adoRST.EOF 'populate your cells here Loop
End Sub
|
|
|
|
|
|
parosky (m)
|
There are various ways by which you canconnect to a DB. If you are new to VB database programming, I will advise you to use Active X Data Object(ADO). There are 2 means of achieving this. 1. Through a ADO data control (Adodc). Place the adodc on your form and click the ellipses next to the connectionstring property. On the Provider tab of the window shown, select your data provider, e.g select Microsoft Jet OLEDB 3.51(or 4.0) depending on the version of microsoft access you are using, that is if you are connecting to microsoft Acess. On the connection tab, use brose to navigate to the path of your database (the access file*.mdb) This is the simplest you need to do, then click on Test Connection button to see you are connected to your database). Then set the Record source properties to indicatewhether you recordset will be from a table, stored procedure or a sql command. You can then bind controls to displayvalue of each field that will be exposed by your recordset. NB Adodc is not in your tool box by default. You need to add it ( click project>> components then select Microsoft ADO DataControl 6.0 (OLEDB). then click apply button and OK. This show the adodc in your toolbox.
2. Similar to the first but gives you a whole lot of control over your data is to program directly against the ADO Object. You will not need to use the Adodc but you sould set a reference to an ADO object. Click Project >>Reference. Then (i) Declare an object variable whose type is ADODB.Connection in the general section of you code or module e.g Dim myConn as ADODB.Connection. then create the object by writing Set myConn = new ADODB.Connection ii)Set the Connection object’s ConnectString property to reflect a valid OLE DB provider, or specify the provider string in the next step, as follows: myConn .ConnectString = "Provider=Microsoft.Jet.OLEDB.3.51;" iii)Call the Connection object’s Open method. If you didn’t specify the ConnectString property in the preceding step, you need to pass the connection string as the first argument to the Open method, as in the following example. Better still reproduce the following format ( to reduce my typing explanations actually) dim dbPath as string myConn.Provider=“Provider=Microsoft.Jet.OLEDB.3.51;” dbPath="c:\my documents\myDB.mdb" myConn.Open dbPath This connect you to the database against which you can now give query to retrieve your recordset. But I feel you are new to database programming. You can ask some more question to let me know I've been helpful and to tell me area where you need more help. I'll check back tommorrow
|
|
|
|
|
|
Zule (m)
|
There are various ways by which you canconnect to a DB. If you are new to VB database programming, I will advise you to use Active X Data Object(ADO). There are 2 means of achieving this. 1. Through a ADO data control (Adodc). Place the adodc on your form and click the ellipses next to the connectionstring property. On the Provider tab of the window shown, select your data provider, e.g select Microsoft Jet OLEDB 3.51(or 4.0) depending on the version of microsoft access you are using, that is if you are connecting to microsoft Acess. On the connection tab, use brose to navigate to the path of your database (the access file*.mdb) This is the simplest you need to do, then click on Test Connection button to see you are connected to your database). Then set the Record source properties to indicatewhether you recordset will be from a table, stored procedure or a sql command. You can then bind controls to displayvalue of each field that will be exposed by your recordset. NB Adodc is not in your tool box by default. You need to add it ( click project>> components then select Microsoft ADO DataControl 6.0 (OLEDB). then click apply button and OK. This show the adodc in your toolbox.
2. Similar to the first but gives you a whole lot of control over your data is to program directly against the ADO Object. You will not need to use the Adodc but you sould set a reference to an ADO object. Click Project >>Reference. Then (i) Declare an object variable whose type is ADODB.Connection in the general section of you code or module e.g Dim myConn as ADODB.Connection. then create the object by writing Set myConn = new ADODB.Connection ii)Set the Connection object’s ConnectString property to reflect a valid OLE DB provider, or specify the provider string in the next step, as follows: myConn .ConnectString = "Provider=Microsoft.Jet.OLEDB.3.51;" iii)Call the Connection object’s Open method. If you didn’t specify the ConnectString property in the preceding step, you need to pass the connection string as the first argument to the Open method, as in the following example. Better still reproduce the following format ( to reduce my typing explanations actually) dim dbPath as string myConn.Provider=“Provider=Microsoft.Jet.OLEDB.3.51;” dbPath="c:\my documents\myDB.mdb" myConn.Open dbPath This connect you to the database against which you can now give query to retrieve your recordset. But I feel you are new to database programming. You can ask some more question to let me know I've been helpful and to tell me area where you need more help. I'll check back tommorrow
sorry, for not replying as at when due it was owing to the fact that i've been very very busy with my school. As you said i'm a newbie vb. and i will also like to know if u have any e-book on vb do u? IF reply= true then pls, send it to my box Else End If once again i would like to thank u for doing me that favour
|
|
|
|
|
|
parosky (m)
|
You don't seem like a newbie cos I've seen some of your contributions. I'm still looking for your email adddress so I can attach one to you or through this site, I'm not browsing on my system now. Take care.
|
|
|
|
|
|
Zule (m)
|
Posted on: June 09, 2006, 10:01:09 PMPosted by: parosky Insert Quote You don't seem like a newbie because I've seen some of your contributions. I'm still looking for your email adddress
@ parosky your right in what u said but one must always lets him self down in ohter to learn from the people above him any way this is mail email address i am waiting for the e-books to be farwarded thanks
|
|
|
|
|
|
parosky (m)
|
@ parosky your right in what u said but one must always lets him self down in ohter to learn from the people above him
Well nobody knows it all. In a forum like this what you gain will depend on what people percieve as the level you are. If you make people believe you are totally new they will be giving you low stuffs. Let people know where you are so that the vibrations will be at a level that will benefit you, not that we'll be telling a guru who is being "humble" about variable declaration. I'm still looking for your email address.
|
|
|
|
|
|
Zule (m)
|
ok, Well nobody knows it all. In a forum like this what you gain will depend on what people percieve as the level you are. If you make people believe you are totally new they will be giving you low stuffs. Let people know where you are so that the vibrations will be at a level that will benefit you, not that we'll be telling a guru who is being "humble" about variable declaration. I'm still looking for your email address.
@parosky my email address is( zule_jojo at yahoo dot co dot uk)
|
|
|
|
|
|
larryshow
|
hellooo seniors, though am new here but yet i will like to contribute . i hv been looking toward an opportunity like this where by nigerians will be able to express and share ideals. its good to hnow something like this exist my contribution is attached.
|
vb.doc
 vb.doc (23.5 KB - downloaded )
|
|
|
|
|
|
|
|
parosky (m)
|
Larryshow I was only able to download a blank word document. May be you'll help attach it again or just copy and past it directly. At times opening attachment is a distraction to some people
|
|
|
|
|
|
dag (m)
|
hi people the lot posted so far is a good primer for database connectivity, but going up from here to where the technology is heading u really have to understand what microsoft wants u to know. OOP is hoopla of the developers world and all that has been said is an implementation of certain classes represented in the ADO Object model. so its all in the model, and the model for ADO is smply 1.connection object 2.command object 3.recordset object
all conn to a database wld basically obey this model, like it has been correctly outlined in earlier postings, if u look carefully ull observe the truth about the model. so just get the model into your head and your good to go, study the properties and methods exposed by these objects and ull better understand what they do best and get intouch with oop its the koko for developers.
|
|
|
|
|
|
femi_ko (m)
|
hope u got the problem solved
|
|
|
|
|
|