General discussion

Locked

Using ADO properties VB6

By muthuraman99 ·
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

This conversation is currently closed to new comments.

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

All Comments

Collapse -

Using ADO properties VB6

by True_Texan In reply to Using ADO properties VB6

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.

Collapse -

Using ADO properties VB6

by muthuraman99 In reply to Using ADO properties VB6

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.

Collapse -

Using ADO properties VB6

by pancras In reply to Using ADO properties VB6

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.

Collapse -

Using ADO properties VB6

by muthuraman99 In reply to Using ADO properties VB6

Poster rated this answer

Collapse -

Using ADO properties VB6

by Biju Nair G In reply to Using ADO properties VB6

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

Collapse -

Using ADO properties VB6

by muthuraman99 In reply to Using ADO properties VB6

Poster rated this answer

Collapse -

Using ADO properties VB6

by muthuraman99 In reply to Using ADO properties VB6

This question was closed by the author

Back to Web Development Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums