DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Opening database in VB6

  1. #1
    Frankie Guest

    Opening database in VB6


    Hi all,

    I don't why I use the below method to retrieve data from the database
    will get error on (Datatype mismatch in criteria expression? please help
    me up... this error is pointing to Set rs=db.OpenRecordset(SQL)......

    Thanks
    Frankie

    Dim rs As Recordset
    Dim db As Database
    Dim SQL As String
    Set db = OpenDatabase("D:\Northwind.mdb")

    SQL = "SELECT * FROM Products WHERE " & _
    "ProductID = '" & DBCombo1.Text & "'"

    Set rs = db.OpenRecordset(SQL)

    DBCombo2.Text = rs!ProductName





  2. #2
    jasonl Guest

    Re: Opening database in VB6


    Frankie,
    by enclosing the DBCombo1.Text in quotes you're telling the database that
    you're passing a string. Northwind is storing the ProductID as a Long Integer.
    Change your SQL to this :
    WHERE ProductID = " & DBCombo1.Text & ";"
    I'm assuming that you're combo is filled with valid ID's. If not you'll want
    to do some validation first.
    -Jason
    "Frankie" <fyip@iprimus.com.au> wrote:
    >
    >Hi all,
    >
    > I don't why I use the below method to retrieve data from the database
    >will get error on (Datatype mismatch in criteria expression? please help
    >me up... this error is pointing to Set rs=db.OpenRecordset(SQL)......
    >
    >Thanks
    >Frankie
    >
    >Dim rs As Recordset
    >Dim db As Database
    >Dim SQL As String
    >Set db = OpenDatabase("D:\Northwind.mdb")
    >
    >SQL = "SELECT * FROM Products WHERE " & _
    > "ProductID = '" & DBCombo1.Text & "'"
    >
    >Set rs = db.OpenRecordset(SQL)
    >
    >DBCombo2.Text = rs!ProductName
    >
    >
    >
    >



  3. #3
    Ajendra Guest

    Re: Opening database in VB6


    The code that Mr. Jasnol has written will work fine if u r usin numeric field
    for the productid else u have to use the followin code

    WHERE ProductID = '" + DBCombo1.Text + "'"

    Ajendra


    "jasonl" <jasonl@wirelesszone.com> wrote:
    >
    >Frankie,
    >by enclosing the DBCombo1.Text in quotes you're telling the database that
    >you're passing a string. Northwind is storing the ProductID as a Long Integer.
    >Change your SQL to this :
    >WHERE ProductID = " & DBCombo1.Text & ";"
    >I'm assuming that you're combo is filled with valid ID's. If not you'll

    want
    >to do some validation first.
    >-Jason
    >"Frankie" <fyip@iprimus.com.au> wrote:
    >>
    >>Hi all,
    >>
    >> I don't why I use the below method to retrieve data from the database
    >>will get error on (Datatype mismatch in criteria expression? please help
    >>me up... this error is pointing to Set rs=db.OpenRecordset(SQL)......
    >>
    >>Thanks
    >>Frankie
    >>
    >>Dim rs As Recordset
    >>Dim db As Database
    >>Dim SQL As String
    >>Set db = OpenDatabase("D:\Northwind.mdb")
    >>
    >>SQL = "SELECT * FROM Products WHERE " & _
    >> "ProductID = '" & DBCombo1.Text & "'"
    >>
    >>Set rs = db.OpenRecordset(SQL)
    >>
    >>DBCombo2.Text = rs!ProductName
    >>
    >>
    >>
    >>

    >



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