Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Question #2 2

Status
Not open for further replies.

eelsar

Technical User
May 20, 2002
36
0
0
US
When writing to a database, what SQL keyword do I use after opening the recordset.

I tried to do the following and it's not working, can anyone help?

Private Sub cmdSave_Click()

Dim rst As New ADODB.Recordset

rst.Open "INSERT INTO * PersonInfo", cnn

rst.AddNew

rst.Fields("IDNumber").Value = txtID.Text
rst.Fields("Name").Value = txtName.Text...


rstCaller.Update

Please help!
eelsar
 
Try this
Private Sub cmdSave_Click()

Dim rst As New ADODB.Recordset

mySQL = "SELECT * FROM tblStockTx"
Set rst = New Recordset
With rst
Set .ActiveConnection = cnn1
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open mySQL
.AddNew
!IDNumber = txtID.Text
!Name = txtName.Text
.Update
.Close
Set rst = Nothing

End With
End Sub Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Sorry I left tblStockTx in - should be your table name of course! Shouldn't cut & paste without checking, should I. Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Or
------------------------------------------------------
Dim Rst As Recordset
Set Rst = New Recordset
With Rst
.Open "PersonInfo", cnn1, adOpenKeyset, adLockOptimistic, adCmdTable
.AddNew
.Fields("IDNumber") = txtID.Text
.Fields("Name") = txtName.Text
.Update
.Close
End With
Set Rst = Nothing
------------------------------------------------------

Which is slightly faster and what MSDN uses...
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
ps.

forgot to mention that personnaly I prefer:
---------------------------------------------
Cnn1.Execute "INSERT INTO PersonInfo(IDNumber,Name) VALUES (" & txtID.text & ",'" & txtName.Text & ")"
---------------------------------------------

If you only are inserting one row at a time. With many rows it is faster with a recordset, waiting to .update until all records have been added. ;-)

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top