Link to home
Start Free TrialLog in
Avatar of kirtirani
kirtirani

asked on

RDO Connection problem

Hi All,

I am very new to VB and now I have started coding in VB. I have to write an application using SQL server as a backend and RDO connection. I am having difficulty in writing the code for RDO. Can anyone help me and can give me the code for establishing the connection and executing the query with RDO thru VB. I need it urgently.

Kirti
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kirtirani
kirtirani

ASKER

Hi ryancys,
thanx for ur program but the thing is I don't want to use the RDO control. and i can use ADO also its upto me. so please suggest which one is better and provide some more useful stuff.
kirti
Here is the code I use. It is in ADO. This will retrive the information from the table. You can use a DSNless connection or one that uses a DSN.

Sub GetSql()
Dim RSSQL As ADODB.Recordset

'This is the dsnless connection
ConnectStrSQL = "Provider=SQLOLEDB.1; Network Library=dbmssocn;Password=Password;User ID=UserName;Initial Catalog=DatabaseName;Data Source=ServerName;"

'This is the DSN connection string. this is the easiest method
ConnectStrSQL = "DSN=Pubs;UID=sa;PWD=pwd;"

'Open Sql Database for updating
Set RSSQL = New ADODB.Recordset
RSSQL.ActiveConnection = ConnectStrSQL
RSSQL.CursorType = adOpenKeyset
RSSQL.LockType = adLockOptimistic
RSSQL.Open "Select * from table"

Hope this helps. Read up on ADO at msdn.microsoft.com/vbasic/technical/articles/ado20/default.asp

Matt
if you have the choice definately use ado instead of rdo.  MS as quit releasing new rdo stuff and don't really support it anymore.
also the above way shown is slow as you have to reconnect to the db every time you want the recordset you should use a connection object if you have to get a bunch of recordsets

ex

dim cn as adodb.connection
dim rs1 as adodb.recordset
dim rs2 as adodb.recordset

set cn = new adodb.connection
set rs1 = new adodb.connection
set rs2 = new adodb.connection

cn.connectionstring = "DSN=mydsn" 'or use a dsn less one
cn.open

dim sql as string
dim sql2 as string
sql = "sql query"
sql2 = "sql2 query"

rs1.open sql, cn, adopenstatic, adlockreadonly
rs2.open sql2, cn, adopenstatic, adlockreadonly

do stuff with rs's

rs1.close
rs2.close
cn.close

set rs1 = nohting
set rs2 = nothing
set cn = nothing
Hi kirtirani,

This might be useful: http://www.able-consulting.com/tech.htm