c#


Rows.Count = 1 when returned dataset consists of an empty row


My query does not return anything but an empty row, since there is no records that meet all the criteria of my query. However, Rows.Count is 1 instead of 0. Here is my query:
SELECT LicenseID
FROM LICENSES
WHERE LicenseType = #LicenseType
AND DriverID = #DriverID
AND CarID IN(
SELECT CarID
FROM CARS
WHERE CarSerial = #CarSerial
AND DriverID = #DriverID
) AND LicenseID IS NOT NULL
AND ((StartDate <= CONVERT(DATETIME, #EndDate))
AND (EndDate >= CONVERT(DATETIME, #StartDate)))
Here is my C# if statement condition that for some reason keeps being true due to row count, even though there is no record meeting criteria:
if (ds != null && ds.Tables[0].Rows.Count > 0)
The database used is SQL Server. This previously seemed to work correctly under Oracle.
To Avoid ERROR:
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
//Then Return a value here or Get the date
foreach (DataRow dr in ds.Tables[0].Rows)
{
String getFirstRow = dr[0].ToString();
//And so on........
}
}
else
{
//Return value if no rows found.
}
}
what I needed to add was just an additional check for "LicenseID <> ''". "LicenseID IS NOT NULL" was not enough since there has been a record meeting all criteria but having LicenseID = "". I believe this has not been an issue with Oracle database, but turned out to be an issue after switching to SQL Server. Thanks for all your comments and suggestions.

Related Links

ServiceStack Client Put request and query parameters
using cookies for session mvc
Create shortcut to Content Files in File System's Setup Project
Submit selected checkboxes only for multiple objects to an MVC controller
MVC4: Authentication still valid but got redirected to login page after app pool recycle
inject C# code to another process and call target functions
Access C++ static methods from C#
Singleton for MongoDB
Data-sync design in .net [closed]
Potentially Dangerous request errors
Using MySQL StoredProcedure in Asp.Net C#
ASP.NET using gmail with smtp error: “A connection attempt failed because the connected party did not properly respond..”
Get values from Gridview to textbox
Xamarin Android Simulator and sending test GPS data to app
Using RestSharp with Gerrit REST API
How to format URL from Eddystone in C#

Categories

HOME
swift3
aix
postsharp
spss
squeak
bitbucket
artifactory
uml-designer
comments
opacity
sequence
pdf-generation
rmarkdown
sitemap
ios-universal-links
openbsd
android-notifications
gpo
descriptor
minimagick
functional-dependencies
datastax-enterprise
jira-zephyr
utc
meteor-accounts
jms-topic
spring-data-gemfire
edirectory
selenium3
deferred
multilanguage
akamai
ilog
abide
device-driver
lex
jquery-inputmask
server-side-swift
wicket-tester
tapply
redbean
directadmin
flume-ng
colorbox
automapper-4
serialversionuid
wink
openpgp.js
r-commander
petapoco
trusted-computing
pyautogui
msiexec
esprima
computed-properties
ldd
git-push
deck.js
init
csc
git-cherry-pick
bytearray
db2-zos
python-rq
containstable
notice
uinavigationitem
bootstrap-tabs
vectordrawable
asp.net-2.0
google-experiments
attiny
xcode5
diffmerge
dirname
im4java
rails-migrations
hotlinking
sendy
sqldatasource
connections
dayofweek
thucydides
google-voice
xcode5.1
nsnumber
wpd
panelgrid
infinity.js
mmo
biztalk-deployment
algol
google-email-audit-api
commonsware
wdm
discussion-board
youtube.net-api
functional-specifications
meego-harmattan
cpack
excellibrary
coderush-xpress
pixel-bender
managed-code

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App