Initial contact with a MySQL database : ' CHANGE THESE VALUES TO YOUR OWN SERVER INFORMATION *********************************************** strConnection = "driver={mysql ODBC 3.51 driver};" _ Set RS = Server.CreateObject("ADODB.Recordset") To insert a record to the database and return the unique ID of the record inserted.
To update a record
To delete a record
To retrieve a record from a database
To retrieve a lot of records from a database (1)
To retrieve a lot of records from a database (2)
|
Quick bit of code : To find duplicates in a DB
' #######################################################
RS.Source = "SELECT *, count(*) cnt FROM TABLE GROUP BY 'FIELD' HAVING cnt > 1"
RS.Open()
DS = RS.GetRows()
RS.Close()
set dbconn = createobject("ADODB.Connection")
dbConn.open strConnection
For myCount = 0 to UBound(DS,2)
dbconn.execute "delete from DATABASE.TABLE WHERE id = " & DS(0,myCount) & " ;"
Next
dbconn.close
set dbconn = nothing
' ####################################################################
|
More Quick code : To word capitalise a string
Function pCase(aString)
If (Len(aString)) Then
aString = LCase(aString)
pCase = ""
cchar = ""
pchar = " "
For i = 1 To Len(aString)
cchar = Mid(aString,i,1)
If cchar = "'" then cchar = "’"
Select Case pchar
Case "/", "\", "-", ":", ";", ".", " ", "(", "&"
cchar = UCase(cchar)
End Select
pchar = cchar
pCase = pCase & cchar
Next
Else
pCase = aString
End If
If InStr(pCase,"(Uk)") then pCase = Replace(pCase,"(Uk)","(UK)")
End Function
|