Question

Locked

Retrieving data from SQL using Visual Basic 6

By karsha ·
Hi,

I need your kind assistance on how to retrieve data from SQL Server using VB6.

The connection string that I used is:(I'm not quite sure on whether my coding is correct.Kindly comment on any errors I have made.)

Public Sub Database_Connection()

Dim i As Integer
Dim strSQL As String
Dim oRS As ADODB.Recordset
Dim oConn As ADODB.Connection

oConn = New ADODB.Connection
oRS = New ADODB.Recordset


strCS = "Provider = SQL.OLEDB.1;" & _
"Integrated Security = SSP1;" & _
"Persist Security Info=False;" & _
"Initial Catalog=BookRecords;" & _
"Data Source = dweappdmy01\eportal;" & _
"UID=sa; PWD=pass;"


oConn.ConnectionString = strCS
oConn.Open

-----------------------------------------------
Below is how I'm currently doing it.Is this correct?

oRS.Recordset

.Fields("Title") = txtTitle.Text
.Fields("Pub_Year") = txtPub.Text
.Fields("Pub_ID") = txtPubID.Text
.Fields("ISBN") = txtISBN.Text
.Fields("Subject") = txtSubject.Text


Thank you.

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Looks good

by dearrohit In reply to Retrieving data from SQL ...

I assume the connection is fine if your variable strCS holds the proper connection string. If you are trying to add a record using a recordset you have to open the recordset first. something like...

oRS.open oConn, "Select * From tablename where 1=2", adopenDynamic,3

Then assign values to the recordset

.Fields("Title") = txtTitle.Text....
.....

then update the recordset
oRS.Update

Collapse -

Looks good

by dearrohit In reply to Retrieving data from SQL ...

I assume the connection is fine if your variable strCS holds the proper connection string. If you are trying to add a record using a recordset you have to open the recordset first. something like...

oRS.open oConn, "Select * From tablename where 1=2", adopenDynamic,3

Then assign values to the recordset

.Fields("Title") = txtTitle.Text....
.....

then update the recordset
oRS.Update


Let me know if this works

Regards...
Rohit

Collapse -

i am also need that

by itsmegopiin In reply to Retrieving data from SQL ...

hi this is surendran did you get answer for your question mean did you establish connection between vb to sql.if you done that one means please send that connection code to my mail id this is my iam also in need of that please reply id:itsmegopiin@yahoo.co.in

Collapse -

helo

by julianne_lagmay In reply to Retrieving data from SQL ...

how are you now?

Back to Networks Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums