Component building in VB

Results 1 to 4 of 4

Thread: Component building in VB

  1. #1
    Srilatha Guest

    Default Component building in VB

    I am trying to build a simple component to query from a SQL database.can someone tell me what&#039s wrong with this code snippet -<BR><BR>rivate cn As ADODB.Connection<BR><BR>Private Sub OpenConnection()<BR> Set cn = New ADODB.Connection<BR> cn.ConnectionString = _<BR> "Provider=SQLOLEDB;" & _<BR> "Data Source=ZMY12-5208;" & _<BR> "Initial Catalog=MKCDB;" & _<BR> "User ID=sa;" & _<BR> "Password="<BR> cn.Open<BR>End Sub<BR>Private Sub CloseConnection()<BR> If cn.State &#060;&#062; 0 Then cn.Close<BR> Set cn = Nothing<BR>End Sub<BR><BR>Public Function RecordCount()<BR> OpenConnection<BR> /* here I set my sql statement and execute it */<BR> CloseConnection<BR>End Function<BR><BR>When I try to test this in vb giving <BR>Set obj = New MKCDB.RecordCount<BR>receive a user-defined type not defined compile error.<BR>I am very new to VB.<BR>Pls. help me figure this out.<BR>Thanks,<BR>Srilatha<BR><BR><BR><BR>

  2. #2
    KPW Guest

    Default RE: Component building in VB

    I had something similar happen to me today. I also am new to using VB (for component development, anyway). I&#039m wondering what would happen if, in your statement<BR><BR>Private cn as ADODB.Connection<BR><BR>you tried either<BR><BR>Private cn as ADODB<BR><BR>or<BR><BR>Private cn as Connection<BR><BR>Just a thought. I have no idea whether this will work but it seems like that was how I solved my problem.

  3. #3
    SPG Guest

    Default RE: Component building in VB

    One of the things you may have missed -- and it is fair to blame Microsoft for putting this outside of the normal code -- is that you need to reference (Project -&#062; References...) the Microsoft ActiveX Data Objects Library 2.1<BR><BR>Continue adding in related libraries until the error goes away. They slow down your compile, but VB claims that it leaves them out of your .dll if you&#039re not really using them.

  4. #4
    Rob King Guest

    Default RE: Component building in VB

    Here&#039s how I would do it....<BR><BR>Public Function GetNewsCount() As Integer<BR> Dim oConn As New ADODB.Connection<BR> Dim oRs As ADODB.Recordset<BR> oConn.Open sConnString<BR> <BR> sSQL = "... SQL select statement here ..."<BR><BR> oRs.Open sSQL, oConn, adOpenDynamic, adLockBatchOptimistic<BR><BR> Set GetNewsCount = oRs.RecordCount<BR> <BR> oRs.Close<BR> set oRs = Nothing<BR> Set oConn = Nothing<BR>End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts