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.
The table is below picture
sql-table.JPG
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();
The table is below picture
sql-table.JPG
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I mis-understood how "rdr.Read()" works, now have better understanding.
Thank you :)
Thank you :)
ASKER
I just need the following for it to work
removed...
if (rdr.Read())
removed...
while (rdr.Read())
{
if (rdr.Read() == false)
SqlCommand comm = new SqlCommand("SELECT * FROM system_clientBenefitList",
comm.CommandType = CommandType.Text;
SqlDataReader rdr = comm.ExecuteReader();
Hope that helps.