Error is:
System.InvalidOperationException: Invalid attempt to read when no data is present. at System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i, Boolean setTimeout) at System.Data.SqlClient.SqlDataReader.GetString(Int32 i) at Login.userLogin_Click(Object sender, EventArgs e) in d:\TEST\attend\Login.aspx.cs:line 47
but i declare a value in that field but still get error here., advance thanks..

Sunny SharmaRank #223 · 11.1K reputationPosted Jun 3, 2013, 1:08 AM EDT
The Exception you showed says that it occured because DataReader didn't find any data in that Row[Column] you tried to access. the best way to track it down is to use try...catch block, so that you can see what actually is happening.
do it like this:
----------------
while(reader.Read()) // Note that execution will enter this loop only if has rows, means you don't need to check reader.HasRows
{
try
{
label4.Text = reader.GetString(11);
}
catch(Exception ex)
{
Consolle.WriteLine("Error in communication: "+ex.Message); // You're free to Show Message or render the message to console or elsewhere.
}
}
-----------------------
Hope it helps :)
Thanks
Kiresh Gangariya52 reputationPosted Jun 3, 2013, 12:20 AM EDT
{
(dataReader.Read() == true)
string userid = Convert.ToString(dataReader["UserId"]);}
Sandeep Singh ShekhawatRank #147 · 15.6K reputationPosted Jun 3, 2013, 12:41 AM EDT
while(dr.Read())
{
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 3, 2013, 12:53 AM EDT
hi,
It might be possible data reader hasn't any value
if (reader.HasRows)
{
while (reader.Read())
{
string userid = Convert.ToString(dataReader["UserId"]);
}
}
hope this will help you.
Ravi ShekharRank #673 · 3.6K reputationPosted Jun 3, 2013, 1:24 AM EDT
use while(dr.read())
{
label4.text = dr.GetString(11);
}
if it doesnot help you. please share your complete code.
Bala43 reputationPosted Jun 3, 2013, 4:07 AM EDT