473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help! Stuck in a datareader loop

Attached is my code. Which I know there is a better way of writing however
this is what I came up with and it works until the value is null or not = to
the <> value.
'Do While rdrSQL.Read()

'While rdrSQL.Read()

' Dim result As String

' result = Trim(rdrSQL.GetString(0))

' Do While result <> Me.txtUserID.Text

' Loop

' If result = Me.txtUserID.Text Then

' MsgBox("Authenticated")

' Dim frm As New Form1

' frm.Show()

' Me.Hide()

' Else

' Me.Close()

' End If

'End While
Nov 20 '05 #1
5 2767
Cor
Hi Mike,
Did not check it all, but in this code I saw some things
'Do While rdrSQL.Read() delete that row I think wthat ill be better
'While rdrSQL.Read()
' Dim result As String
' result = Trim(rdrSQL.GetString(0))
' Do While result <> Me.txtUserID.Text I think you want here
If resul = Me.txtUserId.text then exit while
' Loop change it to end while ' If result = Me.txtUserID.Text Then
' MsgBox("Authenticated")


And please do us a favor, paste your code the next time first in a notepad
and copy it that back before to paste it in the message, makes it more
readable and people will mostly faster help you.

I hope this helps a little bit?
Cor



Nov 20 '05 #2
Um.. perhpas these two lines are your problem:

' Do While result <> Me.txtUserID.Text

' Loop

that, my friend, is an endless loop. You don't change the result
variable inside the loop and so the loop goes on forever.
---
Regards,

Roy Osherove
www.iserializable.com

On Wed, 5 Nov 2003 16:04:19 -0500, "Mike D" <di****@hotmail.com>
wrote:
' Do While result <> Me.txtUserID.Text

' Loop


Nov 20 '05 #3
>> Proudly fixed.<<

I worked most of the night thinking this out and today walked in wit a
result..

Here is the final code that actually works
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
cnSQL.Open()
Dim strsql As String
strsql = "Select username FROM tblSecurity"
Dim cmd As New SqlCommand(strsql, cnSQL)
Dim daSQL As New SqlDataAdapter(strsql, cnSQL)
Dim rdrSQL As SqlDataReader = cmd.ExecuteReader()

Do While rdrSQL.Read()
result = Trim(rdrSQL.GetString(0))
If result = Me.txtUserID.Text Then
MsgBox("Authenticated")
Dim frm As New Form1
frm.Show()
Me.Hide()
Exit Do
End If
Loop
If result <> Me.txtUserID.Text Then
MsgBox("You are not Authorized on the system!")
cnSQL.Close()
rdrSQL.Close()
Me.Close()
End If
cnSQL.Close()
rdrSQL.Close()
Me.Close()
End Sub
"Roy Osherove" <ro**@iserializable.com> wrote in message
news:92********************************@4ax.com... Um.. perhpas these two lines are your problem:

' Do While result <> Me.txtUserID.Text

' Loop

that, my friend, is an endless loop. You don't change the result
variable inside the loop and so the loop goes on forever.
---
Regards,

Roy Osherove
www.iserializable.com

On Wed, 5 Nov 2003 16:04:19 -0500, "Mike D" <di****@hotmail.com>
wrote:
' Do While result <> Me.txtUserID.Text

' Loop

Nov 20 '05 #4
"Mike D" <di****@hotmail.com> wrote...
Here is the final code that actually works


Mike... congrats on getting it "to work" now :you just have to fix it :-) I
don't mean to cause you grief but now that you have the basics figured out
consider how much stuff is going on in an event handler. Not only a ton of
code (unreusable except for cut-and-paste) but you are declaring (and
displaying) a form within it.

You are referencing the txtUserID textbox "directly" rather than passing in
a string, you have cnSQL.Close() and rdrSQL.Close() and Me.Close() in there
twice. The trouble with this kind of thing is that it can only get worse as
more of the app gets completed. Code doesn't get cleaner, it only decays
over time and gets harder to follow as a result.

You can ignore me of course, it works... but think about it at least.

Tom

Nov 20 '05 #5
Cor
Hi Mike,

I did not want to give some critique on your code, you did sound so proud.
And there is nothing wrong to start with doing things even if it is not the
best way. But now that Tom did it a little bit, I give you the advice to
change this.
strsql = "Select username FROM tblSecurity"


If you put in here a where clause (there is a nicer way to do it, but this
shows it fine)

strsql = "Select username from tblSecurity WHERE username = '" & trim(txt)
& "'"

Then your system has only to do one read. and if it exist in the first read
you have it.

What Tom said was more efficiency in coding, it does not give you any
advantage in your program itself. With this it goes a lot faster (except
when you have 1 user than it is slower) :-).

I now can see that it is not, but your approach looks like the webform old
ASP style, but that will soon also change in the way Tom said I think.

But it is good you did found it yourself, it is the same as what I did tell
in my message with the difference you use the do while and I was telling you
the while. The do while you use is more from this time, but I did not wanted
to change your basic code to much then.

I hope this helps a little bit.

Cor
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.