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?

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.