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 7245
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: 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:
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |