简体   繁体   English

使用vb6 ODBC驱动程序从数据mysql计数表的行

[英]count row of table from data mysql with vb6 ODBC Driver

如何使用Visual Basic 6的ODBC DRIVER 3:51 MYSQL功能计算表中的行数?

Dim strDataBaseName As String
Dim strDBCursorType As String
Dim strDBLockType As String
Dim strDBOptions As String
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection

Private Sub Command1_Click()

Dim b as Long
strDBCursorType = adOpenDynamic  'CursorType
strDBLockType = adLockOptimistic   'LockType
strDBOptions = adCmdText         'Options

Set cn = New ADODB.Connection


cn.Open ConnectString()

    With cn
        .CommandTimeout = 0
        .CursorLocation = adUseClient
    End With

    Set rs = New ADODB.Recordset       'Creates record set

    strSQL = "select COUNT(id) from item"

    rs.Open strSQL, cn, strDBCursorType, strDBLockType, strDBOptions


if rs.Eof then
   Goto ExitSub    
else
   <Traverse your recordset here>
end if

ExitSub:

rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

On Error GoTo 0
Exit Sub



Private Function ConnectString() As String
Dim strServerName as String
Dim strDatabaseName as string
Dim strUserName as string
Dim strPassword as string


strServerName = "localhost" 
strDatabaseName = "DatabaseName"
strUserName = "UserName"
strPassword ="Password"

ConnectString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
                "SERVER=" & strServerName & _
                ";DATABASE=" & strDatabaseName & ";" & _
                "USER=" & strUserName & _
                ";PASSWORD=" & strPassword  & _
                ";OPTION=3;"

End Function

Try it. 试试吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将vb6连接到mysql:[Microsoft] [ODBC Driver Manager]找不到数据源名称,并且未指定默认驱动程序 - Connecting vb6 to mysql :[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified vb6连接到mysql:[Microsoft] [ODBC驱动程序管理器]找不到数据源名称,未指定默认驱动程序 - vb6 connecting to mysql :[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified VB6连接到MySQL5.7.16 [Microsoft] [ODBC驱动程序管理器]未找到数据源名称且未指定默认驱动程序 - VB6 connecting to MySQL5.7.16 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified VB6 - 从mySQL表中将数据插入访问表 - VB6 - Inserting a data to an Access Table from a mySQL Table 通过 mysql odbc 驱动程序 3.51 的 vb6 代码创建 DSN 在 Windows 64 位中不起作用 - DSN creation through vb6 code for mysql odbc driver 3.51 not working in windows 64 bit odbc驱动程序不支持请求的属性VB6 - odbc driver does not support the requested properties VB6 从vb6将now()插入mysql - Inserting now() from vb6 into mysql 从 mysql 表子查询中计算行号 - Count row number from a mysql table subquery 从mySql中的表中获取行数 - Getting row count from a table in mySql MYSQL从不同的表中添加行和计数 - MYSQL add row and count from diffrent table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM