?
Solved

Error populating a text using a datareader

Posted on 2005-03-23
4
Medium Priority
?
185 Views
Last Modified: 2010-04-16
I am trying to populate a label and two text boxes. When I debug I can see the label gets populated. However the error message with the text box is:

Method 'object.ToString()' referenced without parentheses


Here is my code:

while (dr.Read())
{
lblPortalUserId.Text = dr["PortalUserId"].ToString();
dr.Read();
txtUserName.ToString = dr["UserName"].ToString();
dr.Read();
txtPassword.ToString = dr["Password"].ToString();
dr.Read();
dr.Close();
}

Any suggestions?
0
Comment
Question by:Sanjeet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:ennixo
ID: 13614357
while (dr.Read())
{
lblPortalUserId.Text = dr["PortalUserId"].ToString();
dr.Read();
txtUserName.Text= dr["UserName"].ToString();
dr.Read();
txtPassword.Text= dr["Password"].ToString();
dr.Read();
dr.Close();
}

you wrote ToString instead of Text for txtUserName and txtPassword properties
0
 
LVL 5

Expert Comment

by:ennixo
ID: 13614424
i don't know what you're trying to do exactly but i think what you want is this :

while (dr.Read())
{
    lblPortalUserId.Text = dr["PortalUserId"].ToString();
    txtUserName.Text= dr["UserName"].ToString();
    txtPassword.Text= dr["Password"].ToString();
}
dr.Close();

dr.Read() reads the next record and stores it in your DataReader, then you get values from the columns of the current record to populate label and textbox
if you .Read() between each column value this won't be the same record AND you will get an Exception at the end of the DataReader

dr.Close() closes the datareader so any data can be read then. if you close it inside your while loop, i think when it will test the next dr.Read() you'll get an Exception too.
0
 
LVL 13

Accepted Solution

by:
dungla earned 1000 total points
ID: 13618154
Remove dr.Read() and dr.Close() at the last line of while loop
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question