|
-
Feb 1st, 2005, 09:05 PM
#1
Thread Starter
Addicted Member
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:
if objrs.bof or objrs.eof then
alert("Record was not found.", "No Record", vbokonly)
else
'do something here
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.

-
Feb 1st, 2005, 09:17 PM
#2
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:
If theDataSet.Tables(0).Rows.Count > 0 Then
' Results Found
Else
' No Results Found
End If
-
Feb 1st, 2005, 09:18 PM
#3
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:
If MyDataSet.Tables("TableName").Rows.Count = 0 Then
'ASP.NEt
Response.WriteLine("Record was not found.")
Else
'Do Something
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
-
Feb 1st, 2005, 09:25 PM
#4
Thread Starter
Addicted Member
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:
dim objconn, sql, objcomm, objreader
objconn = New OLEDBConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & server.MapPath("users.mdb"))
objconn.open()
sql = "SELECT * FROM Employeelist"
objcomm = new OLEDBCommand(sql, objconn)
objreader = objcomm.ExecuteReader()
try
if objreader.read = false
label1.text = "Nothing Found"
objreader.close()
objconn.close()
else
carcat.datasource = objreader
carcat.databind()
objreader.close()
objconn.close()
label1.text = "Data Found"
end if
catch ex as exception
msgbox(ex.message)
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.

-
Feb 1st, 2005, 09:28 PM
#5
Thread Starter
Addicted Member
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.

-
Feb 1st, 2005, 09:30 PM
#6
Re: Finding beginning or ending of database
ASP.Net isnt like ASP, you need to declare your variable types
VB Code:
Dim objconn as OLEDBConnection
Dim sql as String = "SELECT * FROM Employeelist"
Dim objcomm as OLEDBCommand
Dim objreader as OLEDBDataReader
objconn = New OLEDBConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & server.MapPath("users.mdb"))
objconn.open()
objcomm = new OLEDBCommand(sql, objconn)
objreader = objcomm.ExecuteReader()
try
if objreader.read = false
label1.text = "Nothing Found"
objreader.close()
objconn.close()
else
carcat.datasource = objreader
carcat.databind()
objreader.close()
objconn.close()
label1.text = "Data Found"
end if
catch ex as exception
'No MsgBox in ASP.nEt
Response.Write(ex.message)
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
-
Feb 1st, 2005, 09:31 PM
#7
Thread Starter
Addicted Member
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.

-
Feb 1st, 2005, 09:40 PM
#8
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
-
Feb 1st, 2005, 09:45 PM
#9
Thread Starter
Addicted Member
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.

-
Feb 1st, 2005, 10:10 PM
#10
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|