User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 391,661 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,845 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1165 | Replies: 3
Reply
Join Date: Feb 2007
Posts: 7
Reputation: shikha.ch is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
shikha.ch shikha.ch is offline Offline
Newbie Poster

SqlDataReader is not working.

  #1  
Feb 15th, 2007
I want to select single value from Table and display in lable.
I wrote a program :-

 protected static string ConStr = "Data Source=URJIT6;Initial Catalog=Employee;Integrated Security=True";
protected SqlConnection NewCon = new SqlConnection(ConStr);


String QStr = "SELECT Username FROM Register WHERE LoginID=' " + LoginIdtxt.Text.ToString() + "'";
SqlCommand SqlCmd2 = new SqlCommand(QStr, NewCon);
NewCon.Open();

SqlDataReader Reader;

Reader = SqlCmd2.ExecuteReader();

Reader.Read();

l1.Text =Reader("Username");


But This is not working.
and Display error:

Error 1 'Reader' is a 'variable' but is used like a 'method'

It can be solve? Any other solution is possible?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Location: Near Chicago
Posts: 79
Reputation: nikkiH is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
nikkiH's Avatar
nikkiH nikkiH is offline Offline
Junior Poster in Training

Re: SqlDataReader is not working.

  #2  
Feb 15th, 2007
Google is your friend. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Reply With Quote  
Join Date: Jul 2005
Location: Dallas, TX
Posts: 481
Reputation: campkev is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: SqlDataReader is not working.

  #3  
Feb 15th, 2007
i believe square brackets, not parentheses, should be used when referencing a column

l1.Text =Reader("Username");
should be
l1.Text =Reader["Username"];
Reply With Quote  
Join Date: Feb 2007
Posts: 7
Reputation: shikha.ch is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
shikha.ch shikha.ch is offline Offline
Newbie Poster

Re: SqlDataReader is not working.

  #4  
Feb 15th, 2007
Originally Posted by campkev View Post
i believe square brackets, not parentheses, should be used when referencing a column

l1.Text =Reader("Username");
should be
l1.Text =Reader["Username"];



Thanks campkev. it's working. with some other modification.
l1.Text=Reader["Username"].ToString();
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 1:40 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC