| | |
vb6 update record in the database
![]() |
•
•
Join Date: Feb 2005
Posts: 2
Reputation:
Solved Threads: 0
Hello, I have a combo box to select the ID, then it will display the particular record from from the database into the text boxes. And now I'm trying to make a update command button. Then I can just change the record which displaying in the text box. And click update, then the record will be updated in the database. But my cmdUpdate_Click() statement seems doesn't work. Anyone can help please? Cheers
Option Explicit
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub cmbID_Click()
If cmbID.Text = "[Make Selection]" Then Exit Sub
rs.Open "SELECT * FROM co_authors WHERE ID = " & cmbID.Text
txtName.Text = rs!author_Name
txtCountry.Text = rs!country
txtPaperID.Text = rs!paper_ID
rs.Close
End Sub
Private Sub cmdGo_Add_submission_info_Click()
submission_info.Show
update_co_authors.Hide
End Sub
Private Sub cmdUpdate_Click()
Dim ar As ADODB.Recordset
Set ar = New ADODB.Recordset
ar.Open "SELECT * FROM co_authors WHERE ID = " & cmbID.Text
If ar.EOF Then ar.AddNew
Else: ar.Update
End If
ar!author_Name = txtName.Text
ar!country = txtCountry.Text
ar!paper_ID = txtPaperID.Text
ar.Update
End Sub
Private Sub Form_Load()
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\262CS\project\db1.mdb;" & _
"Persist Security Info=False"
rs.Open "SELECT ID FROM co_authors", _
conn, adOpenForwardOnly, adLockReadOnly, adCmdText
cmbID.Text = "[Make Selection]"
Do Until rs.EOF
cmbID.AddItem rs!ID
rs.MoveNext
Loop
rs.Close
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If rs.State = adStateOpen Then rs.Close
If conn.State = adStateOpen Then conn.Close
Set rs = Nothing
Set conn = Nothing
End Sub
Option Explicit
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub cmbID_Click()
If cmbID.Text = "[Make Selection]" Then Exit Sub
rs.Open "SELECT * FROM co_authors WHERE ID = " & cmbID.Text
txtName.Text = rs!author_Name
txtCountry.Text = rs!country
txtPaperID.Text = rs!paper_ID
rs.Close
End Sub
Private Sub cmdGo_Add_submission_info_Click()
submission_info.Show
update_co_authors.Hide
End Sub
Private Sub cmdUpdate_Click()
Dim ar As ADODB.Recordset
Set ar = New ADODB.Recordset
ar.Open "SELECT * FROM co_authors WHERE ID = " & cmbID.Text
If ar.EOF Then ar.AddNew
Else: ar.Update
End If
ar!author_Name = txtName.Text
ar!country = txtCountry.Text
ar!paper_ID = txtPaperID.Text
ar.Update
End Sub
Private Sub Form_Load()
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\262CS\project\db1.mdb;" & _
"Persist Security Info=False"
rs.Open "SELECT ID FROM co_authors", _
conn, adOpenForwardOnly, adLockReadOnly, adCmdText
cmbID.Text = "[Make Selection]"
Do Until rs.EOF
cmbID.AddItem rs!ID
rs.MoveNext
Loop
rs.Close
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If rs.State = adStateOpen Then rs.Close
If conn.State = adStateOpen Then conn.Close
Set rs = Nothing
Set conn = Nothing
End Sub
•
•
Join Date: Mar 2005
Posts: 71
Reputation:
Solved Threads: 3
Hi,
If this problem is still not solve you can try this:::
This is your code:
Private Sub cmdUpdate_Click()
Dim ar As ADODB.Recordset
Set ar = New ADODB.Recordset
ar.Open "SELECT * FROM co_authors WHERE ID = " & cmbID.Text
If ar.EOF Then ar.AddNew
Else: ar.Update
End If
ar!author_Name = txtName.Text
ar!country = txtCountry.Text
ar!paper_ID = txtPaperID.Text
ar.Update
End Sub
'Edit this line
else: ar.update
'make it
else: ar.edit
NOTE: is your ID in your query numeric? if it does you might need to do like this:
ar.Open "SELECT * FROM co_authors WHERE ID = " & val(cmbID.Text)
hope it helps.
Newvbguy
If this problem is still not solve you can try this:::
This is your code:
Private Sub cmdUpdate_Click()
Dim ar As ADODB.Recordset
Set ar = New ADODB.Recordset
ar.Open "SELECT * FROM co_authors WHERE ID = " & cmbID.Text
If ar.EOF Then ar.AddNew
Else: ar.Update
End If
ar!author_Name = txtName.Text
ar!country = txtCountry.Text
ar!paper_ID = txtPaperID.Text
ar.Update
End Sub
'Edit this line
else: ar.update
'make it
else: ar.edit
NOTE: is your ID in your query numeric? if it does you might need to do like this:
ar.Open "SELECT * FROM co_authors WHERE ID = " & val(cmbID.Text)
hope it helps.
Newvbguy
Take a look at this ADO tutorial, it will tell you the correct syntax to use:
http://www.timesheetsmts.com/adotutorial.htm
http://www.timesheetsmts.com/adotutorial.htm
Mark Nemtsas
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
•
•
Join Date: Jan 2009
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
Hello, I have a combo box to select the ID, then it will display the particular record from from the database into the text boxes. And now I'm trying to make a update command button. Then I can just change the record which displaying in the text box. And click update, then the record will be updated in the database. But my cmdUpdate_Click() statement seems doesn't work. Anyone can help please? Cheers
Option Explicit
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub cmbID_Click()
If cmbID.Text = "[Make Selection]" Then Exit Sub
rs.Open "SELECT * FROM co_authors WHERE ID = " & cmbID.Text
txtName.Text = rs!author_Name
txtCountry.Text = rs!country
txtPaperID.Text = rs!paper_ID
rs.Close
End Sub
Private Sub cmdGo_Add_submission_info_Click()
submission_info.Show
update_co_authors.Hide
End Sub
Private Sub cmdUpdate_Click()
Dim ar As ADODB.Recordset
Set ar = New ADODB.Recordset
ar.Open "SELECT * FROM co_authors WHERE ID = " & cmbID.Text
If ar.EOF Then ar.AddNew
Else: ar.Update
End If
ar!author_Name = txtName.Text
ar!country = txtCountry.Text
ar!paper_ID = txtPaperID.Text
ar.Update
End Sub
Private Sub Form_Load()
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\262CS\project\db1.mdb;" & _
"Persist Security Info=False"
rs.Open "SELECT ID FROM co_authors", _
conn, adOpenForwardOnly, adLockReadOnly, adCmdText
cmbID.Text = "[Make Selection]"
Do Until rs.EOF
cmbID.AddItem rs!ID
rs.MoveNext
Loop
rs.Close
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If rs.State = adStateOpen Then rs.Close
If conn.State = adStateOpen Then conn.Close
Set rs = Nothing
Set conn = Nothing
End Sub
Hi,
This is pradeep. I am working on a project to migrate code from Visualbasic to C#.NET. I got confused the usage of Recordset. Can you tell what is the meaning of rs!author_Name in "txtName.Text = rs!author_Name". Is that accessing the member "author_Name" in recordset. Please reply me ASAP. As it is urjent requirement for me..
Regards,
Pradeep.
![]() |
Similar Threads
- How to Update a record in a database (PHP)
- Update SQL database automatically using VB6 (Visual Basic 4 / 5 / 6)
- Problem with update data to database (JSP)
- [Please HELP] Cannot Update Record (PHP)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: How can I load in listview-help
- Next Thread: how or wat tool must i use to display or populate data from data from the database,
| Thread Tools | Search this Thread |
* 6 2007 access activex add age basic beginner birth bmp calculator cd cells.find click client code college connection connectionproblemusingvb6usingoledb creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit excel excelmacro file filename form header iamthwee image inboxinvb internetfiledownload listbox listview liveperson login looping microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading remotesqlserverdatabase report save search sendbyte sites sql sql2008 sqlserver subroutine tags time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web windows






