IDC billing system summary (data connection and query)
The data connection process of the charging system in the data room is to first establish a connection between the ODBC drive and the backend database server, then use the code to establish a connection with ODBC, and then use the code to operate the data on the database server through ODBC, the connection code is as follows:
Public Function connectstring () as string 'establish a remote server data connection connectstring = "provider = sqloledb; Data Source = 192.168.24.176; initial catalog = computerroomcharge_sys; uid = sa; pwd = 123456 "'connectstring =" filedsn = computercharge. DSN; uid = sa; Pwd = 123456 "here is to establish a local data connection end functionpublic function executesql (byval SQL as string) as ADODB. recordset dim ojbcnn as connection dim objrst as recordset dim arry () as string on error goto executesql_error arry () = Split (SQL) set objcnn = new connection objcnn. open connectstring 'determines whether it is not a query statement if instr ("delete, insert, update", ucase (arry (0) Then objcnn. execute SQL msgbox "operation successful", vbokonly + vbexclamation, "prompt" else set objrst = new recordset objrst. open trim (SQL), objcnn, adopenkeyset, adlockoptimistic set executesql = objrst end if 'error handling statement executesql_exit: Set objrst = nothing set objcnn = nothing exit function executesql_error: msgbox "database query error", vbokonly + vbexclamation, "prompt" resume executesql_exit