This is my code which runs perfectly fine in my local, but when I deployed it on iis it gives IndexOutOfRangeException.
The error is this: System.IndexOutOfRangeException: There is no row at position 0.
Please help.
Thanks in advance.
private void showdetail(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
str = "query";
cmd = new SqlCommand(str, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if(ds.Tables[0].Rows.Count > 0) {
lbl_fname.Text = ds.Tables[0].Rows[0]["a"].ToString(); //gives error here
Lbl_lname.Text = ds.Tables[0].Rows[0]["b"].ToString();
lbl_add1.Text = ds.Tables[0].Rows[0]["c"].ToString();
lbl_add2.Text = ds.Tables[0].Rows[0]["d"].ToString();
lbl_city.Text = ds.Tables[0].Rows[0]["e"].ToString();
lbl_state.Text = ds.Tables[0].Rows[0]["f"].ToString();
lbl_county.Text = ds.Tables[0].Rows[0]["g"].ToString();
lbl_country.Text = ds.Tables[0].Rows[0]["h"].ToString();
lbl_taxid.Text = ds.Tables[0].Rows[0]["i"].ToString();
lbl_email.Text = ds.Tables[0].Rows[0]["j"].ToString();
lbl_phone1.Text = ds.Tables[0].Rows[0]["k"].ToString();
lbl_phone2.Text = ds.Tables[0].Rows[0]["l"].ToString();
con.Close();
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('No Data found.')", true);
}
}