murdoch201
Gebruiker
- Lid geworden
- 31 mei 2008
- Berichten
- 336
Hoi,
Ik ben bezig met een MySQL database in Visual Basic 6 (ADODB), alleen stel dat hij een table niet kan vinden, of een waarde niet kan vinden, geeft hij telkens een runtime error terug, en crasht het hele programma. 'On error goto' pakt hij niet aan (geen idee waarom). Iemand die mij kan helpen?
Groetjes,
Ben
Ik ben bezig met een MySQL database in Visual Basic 6 (ADODB), alleen stel dat hij een table niet kan vinden, of een waarde niet kan vinden, geeft hij telkens een runtime error terug, en crasht het hele programma. 'On error goto' pakt hij niet aan (geen idee waarom). Iemand die mij kan helpen?
Code:
Public Function MySQL_FindValuebyString(findattribute As String, table As String, findbyattribute As String, findbyvalue As String) As String
Set Cmd = New ADODB.Command
Cmd.ActiveConnection = DBCon
Cmd.CommandType = adCmdText
'This is your actual MySQL query
Cmd.CommandText = "SELECT " & findattribute & " from " & table & " WHERE " & UCase(findbyattribute) & " = '" & UCase(findbyvalue) & "'"
'Executes the query-command and puts the result into Rs (recordset)
Set Rs = Cmd.Execute
'Loop through the results of your recordset until there are no more records
'Do While Not Rs.EOF
'Put the value of field 'Name' into string variable 'Name'
MySQL_FindValuebyString = Rs(findattribute)
'Move to the next record in your resultset
'Rs.MoveNext
'Loop
Exit Function
End Function
Groetjes,
Ben