473,805 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dbReader creating error

I have a function that is getting an error on my dbReader statment:

C:\VSProjects\C lassLibrary4\Ne wHire.cs(53): 'dbReader' denotes a 'variable'
where a 'method' was expected

Here is the function:
*************** *************** *************** *************** ************
private static void GetNewHire(ref string returnString)
{
DbObject myDbObject = new DbObject();
SqlDataReader dbReader;

SqlParameter[] parameters = {
new SqlParameter("@ ApplicantID",Sq lDbType.Int)};

parameters[0].Value = 241;

dbReader = myDbObject.RunP rocedure("GetNe wHire", parameters);
if (dbReader.Read( ))
{
returnString = dbReader("First Name") + "/n" + dbReader("LastN ame");
<-- error on first dbreader
};
dbReader.Close( );
}
*************** *************** *************** *************** ************

What is wrong with this statement?

Thanks,

Tom
Mar 6 '06 #1
4 1318

"tshad" <ts**********@f tsolutions.com> wrote in message
news:Ow******** ******@TK2MSFTN GP14.phx.gbl...
I have a function that is getting an error on my dbReader statment:

C:\VSProjects\C lassLibrary4\Ne wHire.cs(53): 'dbReader' denotes a
'variable' where a 'method' was expected

Here is the function:
*************** *************** *************** *************** ************
private static void GetNewHire(ref string returnString)
{
DbObject myDbObject = new DbObject();
SqlDataReader dbReader;

SqlParameter[] parameters = {
new SqlParameter("@ ApplicantID",Sq lDbType.Int)};

parameters[0].Value = 241;

dbReader = myDbObject.RunP rocedure("GetNe wHire", parameters);
if (dbReader.Read( ))
{
returnString = dbReader("First Name") + "/n" + dbReader("LastN ame"); <--
error on first dbreader
};
dbReader.Close( );
}


The correct syntax is:

returnString = dbReader["FirstName"] ...

--
Tom Porterfield

Mar 6 '06 #2
Wrong brackets : this should (at the least) use the indexer notation and
casting:

string returnString = ((string)dbRead er["FirstName"]) + "/n" +
((string)dbRead er["LastName"]);

You could lost some of the casting if you used string.Format:

string returnString = string.Format(" {0}\n{1}",
dbReader["FirstName"],dbReader["LastName"]);

The ideal would be to use .GetString(), but this only takes an ordinal - not
worth doing if you only intend reading one line, but if you were reading
2000 it makes sense to use ordinal-based access, finding each ordinal once
(at the top).

Marc
Mar 6 '06 #3
Oops - I inverted the \n vs /n in one of the examples
Mar 6 '06 #4

"Tom Porterfield" <tp******@mvps. org> wrote in message
news:Oh******** ******@TK2MSFTN GP11.phx.gbl...

"tshad" <ts**********@f tsolutions.com> wrote in message
news:Ow******** ******@TK2MSFTN GP14.phx.gbl...
I have a function that is getting an error on my dbReader statment:

C:\VSProjects\C lassLibrary4\Ne wHire.cs(53): 'dbReader' denotes a
'variable' where a 'method' was expected

Here is the function:
*************** *************** *************** *************** ************
private static void GetNewHire(ref string returnString)
{
DbObject myDbObject = new DbObject();
SqlDataReader dbReader;

SqlParameter[] parameters = {
new SqlParameter("@ ApplicantID",Sq lDbType.Int)};

parameters[0].Value = 241;

dbReader = myDbObject.RunP rocedure("GetNe wHire", parameters);
if (dbReader.Read( ))
{
returnString = dbReader("First Name") + "/n" + dbReader("LastN ame");
<-- error on first dbreader
};
dbReader.Close( );
}

The correct syntax is:

returnString = dbReader["FirstName"] ...


That fixed it.

Thanks,

Tom
--
Tom Porterfield

Mar 6 '06 #5

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

Similar topics

13
7214
by: jenny | last post by:
Hi, I am trying to find a VB way that would create a folder on all existing drives - the folder name would be the same on each drive. ie c:\backup, d:\backup, etc. But the folders would only be created if they don't already exist, and if the drive happens to be one a folder cannot be created on (ie a cdrom drive) it would just be skipped without the code generating any errors. your help on this would be most appreciated. jenny
0
1762
by: Robert | last post by:
I get these errors when creating a asp .net web application project in VS 2003 on a remote web server: "Microsoft Development Environment The Web was created successfully, but an error occurred when trying to configure the application root for this Web. Web projects may not operate correctly without an application root. The returned error was: Active Directory Services cannot find the web server. A possible cause for this is an...
6
6128
by: owen | last post by:
Generally speaking, what does it mean when I see a "button" with red text showing this message instead of the control I've dragged onto the web form in Design View.? (But the page works fine at runtime). Does it indicate a problem with References for example? Thanks Owen PS. replies cc'd by email appreciated. owen.southwood@mantix.com
8
3999
by: mcmg | last post by:
Hi, I have an asp app that works fine on a windows xp machine but does not work on a windows 2000 server. I have the following code in my global.asa: <OBJECT RUNAT=Server SCOPE=SESSION ID=MyID
3
3280
by: microsoft.news.com | last post by:
How can I this but using the dbReader instead of the streamreader and get all the items instead of the last one in my text file i'm populating? this works fine: StreamReader sr = new StreamReader("file.txt"); string lines = sr.ReadLine(); while((line = sr.ReadLine()) !=null) { // loops thru and writes the data to the new file
0
2137
by: Ravi Ambros Wallau | last post by:
Hi: I've created a custom control - a grid that uses Infragistics to display some filters, the grid itself, and some buttons. Well, when using this control directly on WebForm, everything works really fine. No problems at all. But, when this control is placed inside a template of an Infragistics UltraWebTab control, somethings stranges happens: 1. When the WebForm is opened, an "Error Creating Control" message is displayed (for container...
2
1330
by: tshad | last post by:
I have a section of code that is giving me an error: ***************************************************************** Invalid attempt to Read when reader is closed. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: Invalid attempt to Read...
2
4944
by: Moses | last post by:
Hi All, Is is possible to catch the error of an undefined element while creating an object for it. Consider we are not having an element with id indicator but we are trying to make the object for it indicator = document.getElementById('indicator');
0
924
by: lpizzle | last post by:
I am embedding a SQL editor in my company's existing program to allow our clients to easily run queries against our database. The current layout is a textbox where they type in the code and a Datagridview. The problem I am having is that it is conceivable that a query they enter will return a lot of records, freezing up the GUI. What I want to be able to do is execute the sql through a DbReader object and feed the Datagridview 1 record (or...
0
9718
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
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10617
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10370
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
10109
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
9186
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
7649
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
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3008
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.