Hi. Could you take a look at my code below. Trying to update all records in the table where the Email = the selected email address in the listbox. The table can contain several instances of this same email address, and I’d like to update all. This is updating, but only the first record. I’ve also tried a Do Until rs.EOF… Loop, but I may not have set that up correctly either
[code] dim sql as String
sql = “SELECT * FROM emailresults WHERE Email LIKE '%” + lbxStudents.Cell(lbxStudents.ListIndex, 0) + “%’”
[quote=103644:@Tim Parnell]If you’re updating the database, Sascha has it.
UPDATE emailresults SET honorRoll = 'True' WHERE email = 'goodstudent@myschool.edu';
You provided a SELECT statement, so I’m not sure what you’re really trying to do (and I can’t make you a more specific query.)
Hope this helps :)[/quote]
Thank you Tim. I was on my iPad on the go and had no time to write an example.
Avoid constructions like " UPDATE … LIKE ‘%einstein@caltech.com%’ " or you can affect wrongly records like frank.einstein@caltech.com.de damaging your data unintentionally.
Can this be used to update every record with a computed value from the same row? I want to add a field what is an MD5 signature of a blob so that I don’t have to push blob data around to check for matches.
My code is something like this:
[code]
sql = "SELECT * FROM mytable"
data = mDB.SQLSelect(sql)
If mDB.Error Then
MsgBox("DB Error: " + mDB.ErrorMessage)
End If
while not data.EOF
data.Edit
If Not mDB.Error Then
data.Field(“Signature”).StringValue = EncodeBase64(Crypto.MD5(data.Field(“sContents”).StringValue))
data.Update
If mDB.Error Then
MsgBox("DB Error: " + mDB.ErrorMessage)
End If
Else
MsgBox("DB Error: " + mDB.ErrorMessage)
End If
data.MoveNext
wend
data.Close
[/code]
Replace it with something like you have suggested in SQL statement like?
Unless I misunderstand your requirement, Todd, I’d suggest getting the database server to do as much as possible for you. It’s been a long time since I used mySQL for anything, but it looks like it has built-in support for a bunch of crypto functions. (At least the linked-to version does…)
These would permit you to execute an UPDATE statement like this: UPDATE mytable SET Signature = MD5(sContents);, which would do it in one go…
yeah. I definitely prefer SQL statements - leveraging the power of the SQL server over brushing through loops and the like. I once knew a DB guy that could work magic with SQL statements. I should have held onto his info. I took DB classes in college for my IS degree but DB admin made me want to throw up. smile