473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

dbReader creating error

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

C:\VSProjects\ClassLibrary4\NewHire.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",SqlDbType.Int)};

parameters[0].Value = 241;

dbReader = myDbObject.RunProcedure("GetNewHire", parameters);
if (dbReader.Read())
{
returnString = dbReader("FirstName") + "/n" + dbReader("LastName");
<-- error on first dbreader
};
dbReader.Close();
}
************************************************** **********************

What is wrong with this statement?

Thanks,

Tom
Mar 6 '06 #1
4 1299

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

C:\VSProjects\ClassLibrary4\NewHire.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",SqlDbType.Int)};

parameters[0].Value = 241;

dbReader = myDbObject.RunProcedure("GetNewHire", parameters);
if (dbReader.Read())
{
returnString = dbReader("FirstName") + "/n" + dbReader("LastName"); <--
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)dbReader["FirstName"]) + "/n" +
((string)dbReader["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**************@TK2MSFTNGP11.phx.gbl...

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

C:\VSProjects\ClassLibrary4\NewHire.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",SqlDbType.Int)};

parameters[0].Value = 241;

dbReader = myDbObject.RunProcedure("GetNewHire", parameters);
if (dbReader.Read())
{
returnString = dbReader("FirstName") + "/n" + dbReader("LastName");
<-- 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
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...
0
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...
6
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...
8
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...
3
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...
0
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...
2
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...
2
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...
0
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.