Connecting database with VB6

Source: Internet
Author: User

'Connect to the SQL database

Private sub bindsqldata ()

Dim cn as new ADODB. Connection

Dim RS as new ADODB. recordset

Rs. cursorlocation = aduseclient

'Strconn = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & App. Path & "\ test. mdb; persist Security info = false" 'connect to access

CN. Open "provider = sqloledb; user id = sa; Password = 5316593; Data Source = 192.168.1.200; database = Bengang 921; persist Security info = true" 'connect to SQL Server oledb

'Cn. Open "provider = msdasql.1; user id = sa; Password = 5316593; Data Source = 192.168.1.200; database = Bengang 921; persist Security info = true" 'connect to SQL Server ODBC

Rs. Open "select a. nodename as sbmc, * From configurationtree A, machine B where a. nodeid = B. nodeid", CN, 1, 1

Set datagrid1.datasource = rs

If Rs. EOF then

Rs. Close

CN. Close

End if

End sub

 

 

 

'Connect to Oracle

Private sub bindoracledata ()

Dim RS as new ADODB. recordset

Dim conn as new ADODB. Connection

Dim strconn as string

'Database connection string

'Connect to a database with a password and add jet oledb: Database Password = 'your password' to the connector'

'Use jet. oledb.3.5 to connect to the Access97 database. Use jet. oledb.4.0 for access2k and later databases.

'Strconn = "provider = Microsoft. Jet. oledb.4.0; Data Source =" & App. Path & "\ test. mdb; persist Security info = false"

Strconn = "provider = msdaora.1; Password = rzeam; user id = rzeam; Data Source = rzeam; persist Security info = true" 'oracle driver

'Use client data curs'

Conn. cursorlocation = aduseclient

'Open access connection

Conn. Open strconn

'If the recordset status is not closed, disable the recordset.

If Rs. State <> adstateclosed then Rs. Close

'Recordser open the table people

Rs. Open "select * From configurationtree A, mm_sbkp B where a. nodeid = (B. ID * 100 + 1)", Conn, adopenkeyset, adlockoptimistic

'Report the total amount of data and test whether data exists

'Msgbox Rs. recordcount

'Bind to DataGrid

Set datagrid1.datasource = rs

End sub

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.