public partial class FrmOnline : System.Web.UI.Page
{
string Query;
SqlCommand cmd;
SqlConnection conn;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
OpenSQLConnection();
SqlCommand cmd = new SqlCommand("select * from Info1 where UID=1", conn);
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read())
{
dr.Read();
TextBox1.Text = dr[0].ToString();
}
}
}
private void OpenSQLConnection()
{
try
{
conn = new SqlConnection("Data Source=(local);Initial catalog=sonia;User ID=sonia;Password=sonia;");
conn.Open();
}
catch (Exception ex)
{
}
}
I m getting error in line TextBox1.Text = dr[0].ToString();
Invalid attempt to read when no data is present.
But the record is there in DB,of UID 1.then y the error is coming.