473,832 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Data Reader Now Rows

I am new to SqlServer, have been using Oracle in a prior life.

I have written a very simple stored procedure in SQL Server and it (the
query) looks like the following...

Select AD_ID, First_Name, Last_Name, User_Type, Phone_Nbr, Email_Addr
From dbo.User_Tbl
Where UPPER(AD_ID) = UPPER(@AD_ID)
and UPPER(User_Type ) = UPPER(@User_Typ e)

I have placed (not shown) the @@ROWCOUNT into the procedure and when I debug
it in Visual Studio 2005, it shows a rowcount of 1, and this is how many rows
I was expecting. A Datareader is returned, but when I perform the While
(dr.Read()) it immedialtely falls out and does not read any records.

Any idea as to what I might be doing wrong such that no records are returned?

Thanks in advance for your assistance!!
Aug 13 '06 #1
6 1478
I have placed (not shown) the @@ROWCOUNT into the procedure and when I debug
it in Visual Studio 2005, it shows a rowcount of 1, and this is how many rows
I was expecting. A Datareader is returned, but when I perform the While
(dr.Read()) it immedialtely falls out and does not read any records.
If executing the query in query analyser works fine then it's probably
something in your .NET code. Could you post the snippet which is failing?
Aug 14 '06 #2
Well I use a lot of general routines to prepare the sql statements and create
the data reader that it becomes a bit complex to show snipits...but here
goes...

Here is the code to create my parameters....
parms[0] = TblUtilites.Get Parameter(TblUt ilites.DataBase Type.SqlServer,
"@AD_ID", ParameterDirect ion.Input, parmValues[0],
TblUtilites.Dat aType.SqlDbType Char, 8);
parms[1] = TblUtilites.Get Parameter(TblUt ilites.DataBase Type.SqlServer,
"@User_Type ", ParameterDirect ion.Input, parmValues[1],
TblUtilites.Dat aType.SqlDbType VarChar, 50);
parms[2] = TblUtilites.Get Parameter(TblUt ilites.DataBase Type.SqlServer,
"@Active_Inacti ve_All", ParameterDirect ion.Input, parmValues[2],
TblUtilites.Dat aType.SqlDbType Char, 1);

Here is the code to create my Command.. (conMgr is a class I have created
which hold my connection, my command, the Data reader...)
try
{conMgr.Sql_Cmd = new SqlCommand(qryN ameOrQryString, conMgr.Sql_Con ); }
catch (Exception e)
{ conMgr.Error_Me ssage = e.Message; }
Here is the code to create the data reader (Again, conMgr holds the command
and data reader)

conMgr.Data_Rea der = (IDataReader)co nMgr.Sql_Cmd.Ex ecuteReader();

Here is the code to read the data reader... (My count is always zero)

IDataReader dr = cm.Data_Reader;
int cnt = 0;

if (dr != null)
{
while (dr.Read())
{ cnt++; }
dr.Close();
}
if (cnt 0)
{ return true; }
else
{ return false; } // always returns false

Aug 14 '06 #3
Well I use a lot of general routines to prepare the sql statements and
create
the data reader that it becomes a bit complex to show snipits...but here
goes...
I can't really tell what's going on because of your helper class. I suspect
the parameters arn't being sent across correctly. Have you tried running SQL
Profiler while executing the code to see what is actually being sent to SQL
Server?
Aug 14 '06 #4
Have never run the profiler...Is there such a thing with Sql Express with the
Server Management Studio installed?
Aug 14 '06 #5
Have never run the profiler...Is there such a thing with Sql Express with
the
Server Management Studio installed?
Hmm, I don't think it comes with SQL Express. Do you have SQL Server
Management Studio Express installed or the full SQL Server Management Studio?
Aug 15 '06 #6
I do not have the full SQL server Management studio installed although I have
a MSDN subscription which I believe provides me that. I read that it does not
come with the version which is freely downloaded from the web.

I changed my stored procedure to write the values passed into the stored
procedure to a temporary database and I discoved what the problem was. I had
changed the code from passing an in-stream SQL statement to a stored
procedure and forgot that I no longer needed to enclose my string variables
in quotes. Silly mistake, but I just could not see it...so obvious that it
could knock you over but...

Thanks for your assistance!!
Aug 16 '06 #7

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

Similar topics

6
4311
by: Natan Vivo | last post by:
I had to built a custom data paging control for my asp.net app and SQL Server. This is what I'm doing: 1. do a SELECT to a SqlDataReader 2. create a DataTable with data from GetSchema() 3. loop trough the datareader using .Read() to the point I want to start 4. add data to DataTable with max of records 5. close the data reader and return
2
7535
by: Joe | last post by:
Anyone can suggest the best method of reading XML and adding data to ListView? Here is the xml data structure:: <xml> <site> <url>http://www.yahoo.com</url> <lastupdate></lastupdate> <check>1</check>
15
2029
by: mosipenko | last post by:
I used to have a problem with DBNull, but now my issue is: System.InvalidOperationException: Invalid attempt to read when no data is present Here's my code behind: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load Dim connectionString As String = "Data Source=server;Initial
2
3786
by: Hrvoje Voda | last post by:
I'm using this store procedure to return data from sql server. SqlDataReader sqlRead = null; System.Data.SqlClient.SqlCommand ProfileBLOBSelect = new System.Data.SqlClient.SqlCommand(); ProfileBLOBSelect.CommandText = "."; ProfileBLOBSelect.CommandType = System.Data.CommandType.StoredProcedure;
1
1710
by: Jim Heavey | last post by:
I have a SQL stored procedures which evaluate the values passed in parameters and then based on those values reads the appropriate records. I run the stored procedure in VS 2005 Debug mode and it successfully executes and I can see the @@ROWCOUNT has the expected number of rows. When I actually do this with my program, the datareader is returned with no execption, but no rows are found in the reader. So I change my Stored procedure...
4
1295
by: shapper | last post by:
Hello, I have an SQL database table with 20 fields: Field_01, Field_02, etc. I am creating a string with StringBuilder. I want to include in my string the fields of one record of the database. The SQL procedure "GetOneRecord" gets one record when its ID is givem. So my problem is how to access each record field and use it in my string.
5
46941
by: cjl | last post by:
P: Stupid question: reader = csv.reader(open('somefile.csv')) for row in reader: do something Any way to determine the "length" of the reader (the number of rows) before iterating through the rows?
0
1014
by: Amitava Maity | last post by:
Hello, I have a data file (data.csv) that is something like this: data, Conductor, ACSR data, diameter, 0.02862 data, cross-section, 0.0004845 data, weight, 1.621 data, Mod, 7000000000 data, Uts, 13450
1
3513
by: =?Utf-8?B?SkI=?= | last post by:
Hello My pgm1 (User Interface Level) passes an empty ArrayList to pgm2 (Business Logic Level). pgm2 then calls pgm3 (Data Access Level) to populate the ArrayList. Question1: When pgm2 gets the ArrayList back from pgm3 how to extract and separate the fields out fo the ArrayLists? Question2: When pgm3 gets ArrayList back from pgm2 how to separate the
0
9795
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10499
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10541
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10212
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7753
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.