首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

vb中如何写数据等查询公共类

2012-01-09 
vb中怎么写数据等查询公共类我vb6语法都不懂,现在需要速成,请问怎样写一个公共类,传入查询字符串,返回查询

vb中怎么写数据等查询公共类
我vb6语法都不懂,现在需要速成,请问怎样写一个公共类,传入查询字符串,返回查询结果
最好从新建类开始说,

[解决办法]
vb6语法都不懂?那估计困难了
[解决办法]
看MSDN
[解决办法]
网上下个代码看下,很简单的!
[解决办法]
c#都能学会,何况vb6呀
[解决办法]
随手写的,错漏之处,还望各位指正:)

VB code
Option Explicit'frmSimpleQuery.frmPrivate Sub Command1_Click()    TestSimpleQueryEnd SubPrivate Sub TestSimpleQuery()    Dim vQuery As New CSimpleQuery    vQuery.MdbFile = App.Path & "\test.mdb"    vQuery.DoQuery ("select * from table1")    Do While (vQuery.RecordSet.EOF = False)        Debug.Print vQuery.RecordSet.Fields("id").Value & "," & _            vQuery.RecordSet.Fields("sname").Value                        vQuery.RecordSet.MoveNext    Loop    End Sub'CSimpleQuery.clsOption ExplicitPrivate m_StrConnectionString As StringPrivate m_StrMdbFile As StringPrivate m_objConnection As ADODB.ConnectionPrivate m_objRecordSet As ADODB.RecordSetPublic Property Get MdbFile() As String    MdbFile = m_StrMdbFileEnd PropertyPublic Property Get RecordSet() As ADODB.RecordSet    Set RecordSet = m_objRecordSetEnd PropertyPublic Property Let MdbFile(ByVal str_MdbFile As String)    m_StrConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & str_MdbFile & _        ";Persist Security Info=False"    ChangeConnection (m_StrConnectionString)        m_StrMdbFile = str_MdbFileEnd PropertyPrivate Sub ChangeConnection(ByVal StrValue As String)    Set m_objConnection = New ADODB.Connection    m_objConnection.ConnectionString = StrValueEnd SubPublic Property Get ConnectionString() As String    ConnectionString = m_StrConnectionStringEnd PropertyPublic Property Let ConnectionString(ByVal StrValue As String)    ChangeConnection (StrValue)End Property'---------------------------------------------------' 过程名    : DoQuery' 时间      : 2010-4-17 11:38' 作者      : 杨过.网狐.cn(csdn bcrun)' 功能      : 按传入的sql语句查询' 说明      :' 备注      :'---------------------------------------------------'Public Sub DoQuery(ByVal strSql As String)    m_objConnection.Open m_StrConnectionString'    If (m_objConnection.state = ObjectStateEnum.adStateClosed) Then''    End If        If (m_objConnection.state <> ObjectStateEnum.adStateOpen) Then        Err.Raise "不能正常创建数据库连接"    End If    Set m_objRecordSet = New ADODB.RecordSet    m_objRecordSet.Open strSql, m_objConnectionEnd Sub 

热点排行