Results 1 to 10 of 10

Thread: Finding beginning or ending of database

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Posts
    162

    Finding beginning or ending of database

    OK, to find out if you are at the end or beginning of a database after an sql you would use say:
    VB Code:
    1. if objrs.bof or objrs.eof then
    2.       alert("Record was not found.", "No Record", vbokonly)
    3. else
    4.       'do something here
    5. end if
    How do you accomplish this in say VB.NET or ASP.NET?
    When life hands you lemons, throw them back.
    My site i'm working on FrogJOBS.com

    Some deep insight for you guys:

    Why do they put brail on drive-up ATMs?
    Whoever put an "s" in the word "lisp" is a mean feller.


  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: Finding beginning or ending of database

    In .NET you'd have a DataSet which is just a collection of Tables and Rows, so once you have it you can use the Count property of the Rows collection for the Table in question to see if any results were returned, i.e.

    VB Code:
    1. If theDataSet.Tables(0).Rows.Count > 0 Then
    2.   ' Results Found
    3. Else
    4.   ' No Results Found
    5. End If

  3. #3
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Finding beginning or ending of database

    This would depend on the code your using to pull the data from the databse.... but generally it would look like this:

    VB Code:
    1. If MyDataSet.Tables("TableName").Rows.Count = 0 Then
    2.       'ASP.NEt
    3.       Response.WriteLine("Record was not found.")
    4. Else
    5.       'Do Something
    6. End If

    Edit: Dammit... i got beat
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Posts
    162

    Lightbulb Re: Finding beginning or ending of database

    actually this is what i got that gives the same effect using an OLEDBConnection, OLEDBCommand, OLEDBDataReader:
    VB Code:
    1. dim objconn, sql, objcomm, objreader
    2.         objconn = New OLEDBConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & server.MapPath("users.mdb"))
    3.         objconn.open()
    4.         sql = "SELECT * FROM Employeelist"
    5.         objcomm  = new OLEDBCommand(sql, objconn)
    6.         objreader = objcomm.ExecuteReader()
    7.         try
    8.             if objreader.read = false
    9.             label1.text = "Nothing Found"
    10.             objreader.close()
    11.             objconn.close()
    12.         else
    13.         carcat.datasource = objreader
    14.         carcat.databind()
    15.         objreader.close()
    16.         objconn.close()
    17.         label1.text = "Data Found"
    18.         end if
    19.             catch ex as exception
    20.                 msgbox(ex.message)
    21.         end try
    I thought I would post my answer in case anyone else wondered about it. I actually found it in another recent post. I couldn't find it until after I post my question. It gives the exact same efffect as the .BOF and .EOF.

    This is for an ASP.NET page.
    When life hands you lemons, throw them back.
    My site i'm working on FrogJOBS.com

    Some deep insight for you guys:

    Why do they put brail on drive-up ATMs?
    Whoever put an "s" in the word "lisp" is a mean feller.


  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Posts
    162

    Re: Finding beginning or ending of database

    Oh, By the way, sorry for not thanking you guys.
    Thanks for the help!!
    When life hands you lemons, throw them back.
    My site i'm working on FrogJOBS.com

    Some deep insight for you guys:

    Why do they put brail on drive-up ATMs?
    Whoever put an "s" in the word "lisp" is a mean feller.


  6. #6
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Finding beginning or ending of database

    ASP.Net isnt like ASP, you need to declare your variable types

    VB Code:
    1. Dim objconn as OLEDBConnection
    2. Dim sql as String = "SELECT * FROM Employeelist"
    3. Dim objcomm as OLEDBCommand
    4. Dim objreader as OLEDBDataReader
    5.  
    6.         objconn = New OLEDBConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & server.MapPath("users.mdb"))
    7.         objconn.open()
    8.    
    9.         objcomm  = new OLEDBCommand(sql, objconn)
    10.         objreader = objcomm.ExecuteReader()
    11.         try
    12.             if objreader.read = false
    13.             label1.text = "Nothing Found"
    14.             objreader.close()
    15.             objconn.close()
    16.         else
    17.         carcat.datasource = objreader
    18.         carcat.databind()
    19.         objreader.close()
    20.         objconn.close()
    21.         label1.text = "Data Found"
    22.         end if
    23.             catch ex as exception
    24.                                 'No MsgBox in ASP.nEt
    25.                 Response.Write(ex.message)
    26.         end try
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Posts
    162

    Re: Finding beginning or ending of database

    it still worked though.
    i declared the variable then set it as an object. I tested it and it works. That's how the .NET tutorials on W3Cschools did it.
    When life hands you lemons, throw them back.
    My site i'm working on FrogJOBS.com

    Some deep insight for you guys:

    Why do they put brail on drive-up ATMs?
    Whoever put an "s" in the word "lisp" is a mean feller.


  8. #8
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Finding beginning or ending of database

    Just because you can jam a sandwich in a vcr doesnt mean its proper... (at least here its not )

    You should always type your variables, otherwise you will not get proper member lists (the drop down thingys in Visual Studio)

    You may not get excally what you want...

    Its just bad programming.

    to help you out put "Option Explicit On" at the very top of all your code pages (this will insure that you cant do a Dim Myvar, you need to do a Dim Myvar as Object)
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Posts
    162

    Re: Finding beginning or ending of database

    Appreciate it. I tried doing the option explicit on, but i'm coding in Dreamweaver actually, because i'm having issues trying to get VS.NET projects to work on my server, anyway, everytime I try to put option explicit on at the top of the page, it tells me I have to put it before any Page or Import statements. It tells me that everytime whether I put it before or not.

    I will try to declare them as objects every time though, but someone should write W3Cschools and tell them to do it the right way, because that was misleading
    When life hands you lemons, throw them back.
    My site i'm working on FrogJOBS.com

    Some deep insight for you guys:

    Why do they put brail on drive-up ATMs?
    Whoever put an "s" in the word "lisp" is a mean feller.


  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Posts
    162

    Re: Finding beginning or ending of database

    ok, so i don't think i'm going to be able to use my method, because it doesn't return the first record in the database when I use the objreader.read = false to check for eof. maybe, is there a way to tell the DataReader to place the cursur at the first record then execute? I would rather not use the DataSet object.
    When life hands you lemons, throw them back.
    My site i'm working on FrogJOBS.com

    Some deep insight for you guys:

    Why do they put brail on drive-up ATMs?
    Whoever put an "s" in the word "lisp" is a mean feller.


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