0

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?

3
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by shikha.ch
0

i believe square brackets, not parentheses, should be used when referencing a column

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

0

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();

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.