Dear Sir,
I have write code but getting error. Please help me to remove this.
Server Error in '/vstrgtpss' Application.
Invalid attempt to read when no data is present.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present. Source Error:
Line 43: {
Line 44: sdr.Read();
Line 45: txtcurrentpass.Text = sdr["Id"].ToString();
Line 46: TextBox2.Text = sdr["vst_nm"].ToString();
Line 47: txtconfirmpass.Text = sdr["idtyp"].ToString();
|
Source File: c:\inetpub\wwwroot\vstrgtpss\webcamimgetest\webcamimge\rvst.aspx.cs Line: 45 Stack Trace:
[InvalidOperationException: Invalid attempt to read when no data is present.]
System.Data.SqlClient.SqlDataReader.CheckDataIsReady(Int32 columnIndex, Boolean allowPartiallyReadColumn, Boolean permitAsync, String methodName) +1768578
System.Data.SqlClient.SqlDataReader.TryReadColumn(Int32 i, Boolean setTimeout, Boolean allowPartiallyReadColumn) +49
System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i) +32
System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) +76
System.Data.SqlClient.SqlDataReader.get_Item(String name) +28
webcamimge.rvst.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\vstrgtpss\webcamimgetest\webcamimge\rvst.aspx.cs:45
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9796650
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +211
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1696
|
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4494.0
namespace webcamimge
{
public partial class rvst : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
String EmplooyeId = Session["emp_id"].ToString();
Label1.Text = " " + EmplooyeId + "";
String emp_nm = Session["emp_nm"].ToString();
Label2.Text = "" + emp_nm + " ";
String dept = Session["dept"].ToString();
Label3.Text = "" + dept + " ";
//Label1.Text = Request.QueryString["emp_id"];
}
protected void Button1_Click(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Id, vst_nm, idtyp,idnm,fa_hu_nm,gndr,phn,vstd_dt,crnt_add,pur_pos FROM vstr2 WHERE idnm = '" + txtconfirmpass6.Text.Trim() + "'"))
// using (SqlCommand cmd = new SqlCommand("SELECT Id, vst_nm, idtyp,idnm,fa_hu_nm,gndr,phn,vstd_dt,crnt_add,pur_pos FROM vstr2 WHERE idnm = " + txtconfirmpass6.Text.Trim() + ""))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
sdr.Read();
txtcurrentpass.Text = sdr["Id"].ToString();
TextBox2.Text = sdr["vst_nm"].ToString();
txtconfirmpass.Text = sdr["idtyp"].ToString();
txtconfirmpass6.Text = sdr["idnm"].ToString();
txtconfirmpass0.Text = sdr["fa_hu_nm"].ToString();
txtconfirmpass1.Text = sdr["gndr"].ToString();
txtconfirmpass3.Text = sdr["phn"].ToString();
txtconfirmpass2.Text = sdr["vstd_dt"].ToString();
txtconfirmpass4.Text = sdr["crnt_add"].ToString();
txtconfirmpass5.Text = sdr["pur_pos"].ToString();
}
con.Close();
}
}
vidchk();
}
}
}