Thursday, March 26, 2009

Connect with DB

Hello....

Here I am giving code to connect to Database and get the data from fields..

connecting with database we use connection string by providing "Provider=... ; Password=...; userid=......;.......... etc)

No need to remember all those things...

follow these steps to get a connection string... very easily

1. Open NotePad
2. Saveas DLP.udl
3. Close NotePad
4. double click on DLP.udl
5. Enter data what it needs
6. close it
7. open DLP.udl with NotePad
8. Copy the String available there and paste it in con.provider="copied string"

'***************** Code **************************
Dim con,rs

Set con=createobject("adodb.connection")
Set con=createobject("adodb.recordset")

con.open="Provider=SQLOLEDB.1;Password=baba;Persist Security Info=True;User ID=Baba;Initial Catalog=baba;Data Source=MICROSOF-BBE3B6\SREE"

rs.open "select * from flight",con

i=0
Do until rs.eof
Dim arr
arr(i)=rs.fields("Userid")
print arr(i)
i=i+1
rs.movenext
Loop

rs.close
con.close

Set con=nothing
Set rs=nothing

'******************* End **********************



Thanks & Regards
Baba Fakruddin.D

No comments:

There was an error in this gadget