Results 1 to 8 of 8

Thread: Odd problem with ADODB.Recordset

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Cecilton, MD USA
    Posts
    278

    Odd problem with ADODB.Recordset

    VB Code:
    1. Private Sub cmdViewSeats_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdViewSeats.Click
    2.         Dim strSeatType As String = cbxSeating.Text
    3.         Dim intGame As Integer = Val(cbxGame.Text)
    4.         Dim objRS As New ADODB.Recordset
    5.         Dim objRS2 As New ADODB.Recordset
    6.         Dim strSQL As String
    7.         Dim strSQL2 As String
    8.  
    9.  
    10.         strSQL = "SELECT Section FROM SectionPricing WHERE Description='" & cbxSeating.Text & "'"
    11.         objRS.Open(strSQL, strConnect)
    12.  
    13.         Do Until objRS.EOF
    14.             strSQL2 = "SELECT SeatNumber FROM Seats WHERE sections='" & objRS.Fields("Section").Value & "'"
    15.             objRS2.Open(strSQL2, strConnect)
    16.             objRS.MoveNext()
    17.             Debug.WriteLine(objRS2.Fields("SeatNumber").Value)
    18.         Loop
    19.     End Sub

    it breaks at objRS.Open(strSQL,strConnect)
    strConnect is declared globaly as

    Dim strConnect As String = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source=Metro Meteors.mdb"

    and that is right because i use it more then once and the times before it work..... i just dont understand why its not working for this new module and its not making sense.....if it works before...why not again???? remember it breaks at that line so its not connecting.....and the SQL statement works for sure cuz i also use that before......

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    It would be mostly in your favour to actually post what the error is .

    "if it works before...why not again????"

    ^^ Its called the effect of the Copy+Paste coder, just because it worked somewhere else dont mean it will work when you move it. Theres literally 1000s of reasons and ways even the most simplistic things can go wrong, which is why these forums have 45 thousand members.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Cecilton, MD USA
    Posts
    278
    An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Metro Meteors Ticket Sales.exe

    Additional information: Unspecified error

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Cecilton, MD USA
    Posts
    278
    when ever i make the strSQL a simple sql statement like "SELECT * FROM SectionPricing" it works......untill it reaches the next recordset opening......i guess its the way im creating the SQL....but what though...????

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Cecilton, MD USA
    Posts
    278
    sorry but i didnt copy paste anything.... i just used the same reasoning from my sub above which works fine to populate a listbox from another RS.

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.         'On program load access the database and populate the seating combo box with the seating types
    4.         Dim objRS As New ADODB.Recordset
    5.  
    6.         Dim strSQL As String
    7.         'Set the connection string
    8.         strConnect = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source=Metro Meteors.mdb"
    9.         'Use SQL statement to access and read the seating types from the PriceSchedule Table
    10.         strSQL = "SELECT SeatingType FROM PriceSchedule"
    11.         'Fill the record set with the data
    12.         objRS.Open(strSQL, strConnect)
    13.         Do Until objRS.EOF
    14.             'Populate the ComboBox with the results
    15.             cbxSeating.Items.Add((objRS("SeatingType").Value))
    16.             objRS.MoveNext()
    17.         Loop
    18.         Dim i As Integer
    19.         For i = 1 To 10
    20.             cbxGame.Items.Add(i)
    21.         Next
    22.         objRS.Close()
    23.  
    24.     End Sub

  6. #6
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    Well, if this one works

    [code]
    strSQL = "SELECT SeatingType FROM PriceSchedule"
    [.code]

    And this one doesnt
    Code:
    strSQL = "SELECT Section FROM SectionPricing WHERE Description='" & cbxSeating.Text & "'"
    Then first of all, try replacing the textbox with a constant value that you KNOW exists, and check that the field name description is corrent and check that its the correct format and not a memo field, which you cant use for any kind of decent querys.

    Code:
    strSQL = "SELECT Section FROM SectionPricing WHERE Description='Test'"

  7. #7
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    try putting square brackets around your table name and field names. You might have chosen one that is an ado key word or something

    strSQL = "SELECT [Section] FROM SectionPricing WHERE [Description]='Test'"
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Cecilton, MD USA
    Posts
    278
    thanks nswan that did the trick. and my one objrs2 statement didnt work ....but that was do to a value type mismatch which i quickly took care of.

Posting Permissions

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



Click Here to Expand Forum to Full Width