Invalid attempt to read data when no data is present
I have a Sql Dbase in C#[built before i got to my present job,creator is
gone], and it was fine until last week. On the first page
clerk_search.aspx it searches SQL for people and posts back to a datagrid
thats fine. There is a ASP Image button thats clicked on and it goes
forward to the next page, to enter the reason the for the customers visit
with loaded fields about the customer that post back. For some persons the
next page populates, for others it does not. The SQL statement used checks
out fine in query analyzer, i dont understand. I dont think its the reader
because others are logged in fine, and the other customers are present in
the rows in SQL and can be queried just fine. All is posted below, I am
not savvy with coding, please assist.
`System.InvalidOperationException: Invalid attempt to read when no data
is present.
Line 40: SqlDataReader reader2 = cmd.ExecuteReader();
Line 41: reader2.Read();
Line 42: LblLName.Text = "" + reader2["LAST_NAME"];
Line 43: LblFName.Text = "" + reader2["FIRST_NAME"];
Source File: "....clerk_create.aspx.cs" Line: 42
[InvalidOperationException: Invalid attempt to read when no data is
present.]
System.Data.SqlClient.SqlDataReader.GetValue(Int32 i) +118
System.Data.SqlClient.SqlDataReader.get_Item(String name) +27
clerk_create.Page_Load(Object sender, EventArgs e)
in "c:......\clerk_create.aspx.cs:42
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
Object t,
EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e)
+35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint) +627
Here is the actual: ....clerk_create.aspx.cs
public partial class clerk_create : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["us"] == null)
{
Response.Write("Sorry, you do not have access to this page.
Please see
data systems.");
Response.End();
}
if (!IsPostBack)
{
using (SqlConnection connection = new SqlConnection
(WebConfigurationManager.ConnectionStrings["walkin2"].ConnectionString))
{
TextBox txtsct =
(TextBox)Page.PreviousPage.FindControl("Txtsct");
Txtsct.Text = txtsct.Text;
TextBox txt =
(TextBox)Page.PreviousPage.FindControl("Txtssn");
Txtssn.Text = "" + txt.Text;
connection.Open();
string strsql2 = "SELECT dbo.table_name.SSN,
dbo.table_name.LAST_NAME,
dbo.table_name.FIRST_NAME, dbo.table_name.MIDDLE_INITIAL,
dbo.table_name.COMPONENT_CODE, dbo.table_name.PRESENT_CODE
FROM
dbo.table_name INNER JOIN dbo.table_name ON
dbo.table_name.SSN = '" +
Txtssn.Text + "')";
SqlCommand cmd = new SqlCommand(strsql2, connection);
SqlDataReader reader2 = cmd.ExecuteReader();
reader2.Read();
LblLName.Text = "" + reader2["LAST_NAME"];
LblFName.Text = "" + reader2["FIRST_NAME"];
`
No comments:
Post a Comment