Hey guys,
I would like to know how to replace values in your database via ADODB.
Example:
(I would want to replace the value LOCATION of ID 1001 which is Oliver to Laguna.)
ID NAME LOCATION
1001 | Oliver | Quezon City
1002 | Paul | Laguna
I've made 2 buttons, 1 is to search the other one is to insert. Is my logic right? Or is there another way?
Here are my codes:
(FOR SEARCHING)
Set cn = New ADODB.Connectio n
Set rs = New ADODB.Recordset
cn.Open "DSN=db1"
b = (InputBox("Ente r Student Number"))
Set rs = cn.Execute("sel ect * from Student_Info")
While rs.EOF = False And rs.BOF = False
If b = rs.Fields("Stud ent_No") Then
Text3.Text = rs.Fields("Stud ent_No")
MsgBox ("user found")
Exit Sub
Else
rs.MoveNext
End If
Wend
MsgBox ("user not found")
(FOR INSERTING):
Set cn = New ADODB.Connectio n
Set rs = New ADODB.Recordset
cn.Open "DSN=db1"
Set rs = cn.Execute("sel ect * from Student_Info")
While rs.EOF = False And rs.BOF = False
If rs.Fields("Stud ent_No") = Text3.Text Then
er = Combo1.Text
et = Text3.Text
-->'Set rs = cn.Execute("Ins ert into Student_Info (course) values ('" & Combo1.Text & "' ) where rs.fields("Stud ent_No")=text3. text")
-->'Set rs = cn.Execute("Upd ate Student_Info SET course = er Where Student_No = et;")
rs.Fields("cour se") = er
MsgBox ("pasok")
Exit Sub
Else
rs.MoveNext
End If
Wend
End Sub
Legend:
(-->) Neither one of these codes does what i want them to.
Is there a problem of syntax or logic, me and my group are kinda stuck at this point. Please help.
Thanks in advance.
I would like to know how to replace values in your database via ADODB.
Example:
(I would want to replace the value LOCATION of ID 1001 which is Oliver to Laguna.)
ID NAME LOCATION
1001 | Oliver | Quezon City
1002 | Paul | Laguna
I've made 2 buttons, 1 is to search the other one is to insert. Is my logic right? Or is there another way?
Here are my codes:
(FOR SEARCHING)
Set cn = New ADODB.Connectio n
Set rs = New ADODB.Recordset
cn.Open "DSN=db1"
b = (InputBox("Ente r Student Number"))
Set rs = cn.Execute("sel ect * from Student_Info")
While rs.EOF = False And rs.BOF = False
If b = rs.Fields("Stud ent_No") Then
Text3.Text = rs.Fields("Stud ent_No")
MsgBox ("user found")
Exit Sub
Else
rs.MoveNext
End If
Wend
MsgBox ("user not found")
(FOR INSERTING):
Set cn = New ADODB.Connectio n
Set rs = New ADODB.Recordset
cn.Open "DSN=db1"
Set rs = cn.Execute("sel ect * from Student_Info")
While rs.EOF = False And rs.BOF = False
If rs.Fields("Stud ent_No") = Text3.Text Then
er = Combo1.Text
et = Text3.Text
-->'Set rs = cn.Execute("Ins ert into Student_Info (course) values ('" & Combo1.Text & "' ) where rs.fields("Stud ent_No")=text3. text")
-->'Set rs = cn.Execute("Upd ate Student_Info SET course = er Where Student_No = et;")
rs.Fields("cour se") = er
MsgBox ("pasok")
Exit Sub
Else
rs.MoveNext
End If
Wend
End Sub
Legend:
(-->) Neither one of these codes does what i want them to.
Is there a problem of syntax or logic, me and my group are kinda stuck at this point. Please help.
Thanks in advance.
Comment