dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Brand New to SQL, need help

  1. #1
    MattM Guest

    Brand New to SQL, need help


    I am trying to search two tables and see if any matches will pop up in their
    fields. I have no knowledge of SQL and without it the program takes way too
    long to run. Here is the SQL and code that I am trying to use. Any help at
    all would be great!

    Private Sub cmdSearch1_Click()
    Dim SDN As Database
    SDN = "C:\WINNT\Profiles\mmodrak\Desktop\OFACProgDB.mdb"
    Dim sqlStr As String
    frmMain.datAcct.Recordset.MoveFirst
    Do Until frmMain.datAcct.Recordset.EOF
    For i = 2 To 100
    sqlStr = "select * from SDN where ListInfo like '*"
    sqlStr = sqlStr + accts.Recordset.Fields(i)
    sqlStr = sqlStr + " *'"
    {I know that right here I need search and see if there are any matches,
    if any matches do come up I need to do a print of the two matched fields.}


    End Sub

  2. #2
    Petey Guest

    Re: Brand New to SQL, need help


    Well, the real problem is that you are declaring SDN as a database but not
    actually creating an instance of the database. Depending on which database
    access technology you are using, the top of your procedure should look something
    like this.

    '//DAO (Data Access Objects):

    Private Sub cmdSearch1_Click()
    Dim SDN as new database
    Dim sDataLoc as string

    sDataLoc = "C:\WINNT\Profiles\mmodrak\Desktop\OFACProgDB.mdb"
    set SDN = dbengine.OpenDatabase(sDataLoc)

    '//Use this code if you are connecting via ADO (ActiveX Data Objects)

    Private sub cmdSearch1_click()

    Dim SDN as new ADODB.Connection
    Dim sDataLoc as string
    Dim cString as string

    sDataLoc = "C:\WINNT\Profiles\mmodrak\Desktop\OFACProgDB.mdb"
    cString = "Provider=Microsoft.OLEDB.Jet.3.51;"
    cString = cString & "Database=" & sDataLoc
    SDN.Open (cString)
    '//if you have a DSN set up for the database file, you
    '//can use its name for your cString value instead of the
    '//longer string I have provided up above

    Your SQL statment and Declaration looks fine, though if you are using this
    on an Access database, you want to end it with a semi-colon (

    good luck and keep at it
    Its frustrating at times but ultimately worth the effort.



    >Private Sub cmdSearch1_Click()
    >Dim SDN As Database
    >SDN = "C:\WINNT\Profiles\mmodrak\Desktop\OFACProgDB.mdb"
    >Dim sqlStr As String
    >frmMain.datAcct.Recordset.MoveFirst
    >Do Until frmMain.datAcct.Recordset.EOF
    > For i = 2 To 100
    > sqlStr = "select * from SDN where ListInfo like '*"
    > sqlStr = sqlStr + accts.Recordset.Fields(i)
    > sqlStr = sqlStr + " *'"
    > {I know that right here I need search and see if there are any matches,
    >if any matches do come up I need to do a print of the two matched fields.}



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center