Hi all,
Feel like I'm trying to run before I can walk a little here - very new to
ASP.Net so please bare with me..
I am trying to return a count based on criteria (username) entered by the
user, and then the corresponding userid, forename, surname etc etc...
Below is the code (or some there of) that I am using, but I keep getting an
error...
strSQL = "SELECT CAST(Count(UserID) AS int) AS RecordCounter FROM
view_UserLogon WHERE UPPER(Username) = '" & UCase(strUsername) & "';"
strSQL = strSQL & "SELECT UserID, Forename, Surname FROM view_UserLogon
WHERE UPPER(Username) = '" & UCase(strUsername) & "'"
objCommand = New SqlCommand(strSQL, objConnection)
objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConn ection)
If objDataReader.HasRows Then
While objDataReader.Read()
intRecordCounter = objDataReader("RecordCounter")
If intRecordCounter = 0 Then
Label4.Text = "Sorry, the username supplied does not exist
within the Clinical Portal"
ElseIf intRecordCounter = 1 Then
objDataReader.NextResult()
Label4.Text = "Everythings ok so far."
Label5.Text = objDataReader("UserID")
ElseIf intRecordCounter > 1 Then
Label4.Text = "Error: More than one user exists within the
Clinical Portal with the same username."
End If
End While
Else
' Here, if no rows we return then the record counter failed.
Label4.Text = "Error : Unable to return record count."
End If
I read that you can put 2 or more SQL statements in the one string,
splitting them with a semicolon, and then use both from the datareader in
the code, I've tried following an example but it's not going quite to
plan...
The error generated from entering a username that is in the database (and
only one instance of) - is this :
System.IndexOutOfRangeException: RecordCounter
The line it doesnt like is :
intRecordCounter = objDataReader("RecordCounter")
The example online had the first instance of the results referred to as (0),
ie strString = objDataReader(0) - I've tried this and whilst it then steps
over this error, it generates another for the line of code which should put
text in Label5.
If anyone could shed some light on this one for me I would be most
grateful - please remember I am NEW to this, so answers written/explained in
simple english would be appreciated ;o)
Regards
Rob 2 7243
After you go to the next result, you have to call Read to move the cursor to
the first row of that result set.
"Rob Meade" <ro**********@NOSPAMubht.swest.nhs.uk> wrote in message
news:u4**************@TK2MSFTNGP12.phx.gbl... Hi all,
Feel like I'm trying to run before I can walk a little here - very new to ASP.Net so please bare with me..
I am trying to return a count based on criteria (username) entered by the user, and then the corresponding userid, forename, surname etc etc...
Below is the code (or some there of) that I am using, but I keep getting
an error...
strSQL = "SELECT CAST(Count(UserID) AS int) AS RecordCounter FROM view_UserLogon WHERE UPPER(Username) = '" & UCase(strUsername) & "';" strSQL = strSQL & "SELECT UserID, Forename, Surname FROM view_UserLogon WHERE UPPER(Username) = '" & UCase(strUsername) & "'"
objCommand = New SqlCommand(strSQL, objConnection)
objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConn ection)
If objDataReader.HasRows Then
While objDataReader.Read()
intRecordCounter = objDataReader("RecordCounter")
If intRecordCounter = 0 Then
Label4.Text = "Sorry, the username supplied does not exist within the Clinical Portal"
ElseIf intRecordCounter = 1 Then
objDataReader.NextResult()
Label4.Text = "Everythings ok so far." Label5.Text = objDataReader("UserID")
ElseIf intRecordCounter > 1 Then
Label4.Text = "Error: More than one user exists within the Clinical Portal with the same username."
End If
End While
Else
' Here, if no rows we return then the record counter failed. Label4.Text = "Error : Unable to return record count." End If
I read that you can put 2 or more SQL statements in the one string, splitting them with a semicolon, and then use both from the datareader in the code, I've tried following an example but it's not going quite to plan...
The error generated from entering a username that is in the database (and only one instance of) - is this :
System.IndexOutOfRangeException: RecordCounter
The line it doesnt like is :
intRecordCounter = objDataReader("RecordCounter")
The example online had the first instance of the results referred to as
(0), ie strString = objDataReader(0) - I've tried this and whilst it then steps over this error, it generates another for the line of code which should
put text in Label5.
If anyone could shed some light on this one for me I would be most grateful - please remember I am NEW to this, so answers written/explained
in simple english would be appreciated ;o)
Regards
Rob
"Marina" wrote... After you go to the next result, you have to call Read to move the cursor
to the first row of that result set.
Hi Marina,
Many thanks for your reply - all working now :)
Rob This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jacko |
last post by:
Hi guys,
Say I made a SELECT statement to my sql DB that would return 50 rows
that I will use a sqldatareader to access. Instead of iterating through
each and every row of the datareader, I'd...
|
by: Thomas Scheiderich |
last post by:
I have 2 dropdowns that are exactly the same and I don't want to re-read
for each.
Is there a way to do something like below where I read the data, bind to
depCity1 and then bind to destCity2. ...
|
by: Mark |
last post by:
Hi all, quick question , a DataView is
memory resident "view" of data in a data table therefore once populated you
can close the connection to the database. Garbage collection can then be
used to...
|
by: Varangian |
last post by:
Hi all,
the question I want to ask if the conversion of a DataReader to a Table
looping through the DataReader is better than using the Fill Method of
the DataAdapter... I'm asking because...
|
by: dejavue82 |
last post by:
This is the result of a JOINed query:
question answer
1 a1
1 a2
1 a3
1 a4
2 a1
2 a2
|
by: fniles |
last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataReader.
As I read data from tblA, I want to populate tblB. I use SQLDataReader for
both tables. I do not use thread.
When I ExecuteReader on tblB, I...
|
by: Piotrekk |
last post by:
I have a question related to DataReader
Suppose a lot of the data is being retrieved from database. To make
use of the advantage of datareader over dataset this data should be
transferred in...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |