Discussion Locked

Using ADO properties VB6

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am a beginner who is practising the utlisation of ADODB (vb6) us databases as it is independent of OS.Here I have a problem - If I want to add new data/records then with "ADDNEW" I am not successful.In fact there is a sample code in MSDN (July99 release) indicating the above,but I have tried but not successful.Can anyone help me?
Thanks in advanece.
Regards

Muthu

7 replies

by true_texan

I am not sure how what else you have done with this, but after you have defined your recordset and database

public rs as recordset
public db as database

, you use .addnew, define what you're
adding, i.e.

rs.addnew

then you'll assign your fieldname to the database:

rs!Recordsetname = txtFieldname.Text

finally, you have to use .update

rs.update

The .update is what actually writes the text to the database. Hope this helps.

by muthuraman99

I have tried as mentioned above,but not successful.In fact the syntax tried by me is almost similar to the sample code given in MSDN but still not working.I am getting an error message "The operation requested by the application is not supported by the provider".
This is quite ironic.I am at the end of my wits.

by pancras

Here some sample code to create a msSqlServer recordset rstEmployees

Dim cnn1 As ADODB.Connection
Dim rstEmployees As ADODB.Recordset
Dim strCnn As String
Dim varDate As Variant

' Open connection.
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
Set cnn1 = New ADODB.Connection
cnn1.Open strCnn

' Open employee table.
Set rstEmployees = New ADODB.Recordset
rstEmployees.CursorType = adOpenKeyset
rstEmployees.LockType = adLockOptimistic
rstEmployees.Open "employee", cnn1, , , adCmdTable
The last three rows are critical regarding things you can do with the recordset (like inserting,updating etc.). The possible settings here aredetermined by the choice of the provider (here msSqlServer -defined by provider=sqloledb).
My gues is that you have choosen a provider wich does not support inserting or you have choosen a wrong cursorstype.

by biju nair g

Dear Muthu,

I hope this works for you.
Place the following code in a command click event.
'Start-------********-----------
Dim cn as New ADODB.Connection
Dim rs as New ADODB.Recordset

'If the connection is open then close
If cn.State = 1 then cn.close
'Establish a connection using a Data Source Name (DSN)/ You can do this using a DSN less connection string.

cn.open "DSN Name"
'Open the recordset with lockoptimistic(2) and for writing(3)
rs.Open "Select * from TableName",cn,2,3If rs.State = 1 then rs.close
rs.Addnew
rs("empName") = "Carter"
rs("empAddress") = "Add1"
rs("empSal") = 5000
rs.Update

If rs.State = 1 then rs.close
cn.Close

'End---------************--------

Thank You
Biju Nair G

This discussion is closed to new replies.