Link to home
Start Free TrialLog in
Avatar of dipster307
dipster307

asked on

what is wrong with my sql reader, doest display any records.

I have the following code in asp.net using c#. My sqldatareader doesnt display data from the table, when there is data in it.

            conn.Open();
            SqlCommand comm = new SqlCommand("SELECT * FROM system_clientBenefitList", conn);
            SqlDataReader rdr = comm.ExecuteReader();

            //lblOutput2.Text += rdr["pensionID"].ToString() + "OUT";
            //lblOutput2.Text += rdr["lifeAssuranceID"].ToString() + "OUT";

            while (rdr.Read())
            {
                if (rdr.Read() == false)
                {
                    lblOutput2.Text += rdr["factfindID"].ToString();
                    lblOutput2.Text += rdr["pensionID"].ToString();

                    if (rdr["pensionID"].ToString() == "Add")
                    {
                        divPension.Style["display"] = "block";
                    }
                    else
                    {
                        divPension.Style["display"] = "none";
                    }
                    if (rdr["lifeAssuranceID"].ToString() == "Add")
                    {
                        divPension.Style["display"] = "block";
                    }
                    else
                    {
                        divPension.Style["display"] = "none";
                    }
                }
                else
                {
                    lblOutput2.Text += rdr.Read().ToString();
                }
            }

                rdr.Close();

Open in new window



The table is below picture
sql-table.JPG
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

Try this:

SqlCommand comm = new SqlCommand("SELECT * FROM system_clientBenefitList", conn);
comm.CommandType = CommandType.Text;
SqlDataReader rdr = comm.ExecuteReader();

Hope that helps.
Avatar of dipster307
dipster307

ASKER

sorry that didnt work, and why would it, its not doing anything.

The thing is this works in Visual Studio 2008 but when I used the coding in Visual Studio 2010. It doesnt, is it my coding, or am I going mad?
ASKER CERTIFIED SOLUTION
Avatar of Obadiah Christopher
Obadiah Christopher
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I mis-understood how "rdr.Read()" works, now have better understanding.

Thank you :)
I just need the following for it to work

if (rdr.Read())
            

Open in new window


removed...

  while (rdr.Read())
            {
                if (rdr.Read() == false) 

Open in new window