The problem of connection between VB and SQL Server database

Source: Internet
Author: User
server|sqlserver| Data | database | database connection | problem

Recently compiled a material management system, with vb6.0+sqlserver2000, in the writing ExecuteSQL function error,

Public Function ExecuteSQL (ByVal sql As String, msgstring as String) as ADODB. Recordset
Dim CNN as ADODB. Connection
Dim rst as ADODB. Recordset
Dim Stokens () as String
On Error GoTo Executesql_error
Stokens = Split (SQL)
Set cnn = New ADODB. Connection
Cnn. Open connectstring
If InStr ("Insert,delete,update", ucase$ (Stokens (0)) Then
Cnn. Execute SQL
msgstring = Stokens (0) & "Query sucessful"
Else
Set rst = New ADODB. Recordset
Rst. Open trim$ (SQL), CNN, adOpenKeyset, adLockOptimistic
Set ExecuteSQL = rst
msgstring = "Query to" & rst. RecordCount & "Record"
End If
Executesql_exit
Set rst = Nothing
Set cnn = Nothing
Exit Function
Executesql_error
msgstring = "Query Error" & Err.Description
Resume Executesql_exit

End Function

Public Function connectstring () as String
ConnectString = "Filedsn=material.dsn;uid=sa;pwd=sa"
End Function

An error occurred while precompiling execution, prompting the subroutine or function undefined, and pointing to executesql_exit, I have added the Microsoft ACTIVEX OBJECTS 2.6 LIBRARY and the data source is set



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.