Inner exception :System.InvalidOperationException: Invalid attempt to read when no data is present. at getData(int id)at PopulatePage() at Page_Load(Object sender, EventArgs e) at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
private static SqlConnection _connection; public static SqlConnection Connection { get { if (_connection == null) { SecurityClass Secure = new SecurityClass(); _connection = Secure.PublicConnection(); } return _connection; } } public static object getData(int id) { using (SqlCommand cmd = new SqlCommand("spGetdata", Connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", id); try { if (Connection.State != ConnectionState.Open) { Connection.Open(); } using (SqlDataReader sqlReader = cmd.ExecuteReader()) { sqlReader.Read(); } } catch (Exception ex) { throw ex; } finally { if (Connection.State == ConnectionState.Open) { Connection.Close(); } } } return object; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)