Posts: 21
Name: Hesham
Location: Ismailia , EGYPT
|
thats so good , i understand ,,, i did what you said and its return the field am equal with the EmployeeID ,,, my problem is here ,,, i will explain i hope you can help me because i try to search about the problem but am lost and confused ,,, so i have aspx page okay ,,, and this page include 2 objectdatasource ,, ok and one listbox and one details view all am try to do ,, is bind the list and fill it with the method that return the EmployeeID and this control is bind and work well and i want when choice EmployeeID gives me the Employee Details Data and here is the method am work with from my EmployeeDB.cs file
publicEmployeeDetails GetEmployee(int employeeID)
{
SqlConnection con = newSqlConnection(connectionString);
SqlCommand cmd = newSqlCommand("GetEmployee", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(newSqlParameter("@EmployeeID", SqlDbType.Int, 4));
cmd.Parameters["@EmployeeID"].Value = employeeID;
try
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
// Get the first row.
reader.Read();
EmployeeDetails emp = newEmployeeDetails((int)reader["EmployeeID"], (string)reader["FirstName"],(string)reader["LastName"], (string)reader["TitleOfCourtesy"]);
reader.Close();
return emp;
}
catch (SqlException err)
{
// Replace the error with something less specific.
// You could also log the error now.
thrownewApplicationException("Data error.");
}
finally
{
con.Close();
}
}
-------------------------------------------------------
so the page is work well till i press on the listbox item and it should postback and bring me the employee details data ,,,,,,,, i recieve this error page
Server Error in '/Heko9Test' Application.
EmployeeID
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.IndexOutOfRangeException: EmployeeID
Source Error:
Line 137: // Get the first row.Line 138: reader.Read();Line 139: EmployeeDetails emp = new EmployeeDetails((int)reader["EmployeeID"], (string)reader["FirstName"],(string)reader["LastName"], (string)reader["TitleOfCourtesy"]);Line 140: reader.Close();Line 141: return emp;
Source File: C:\Documents and Settings\Heko\My Documents\Visual Studio 2005\Projects\Heko9Test\DataBaseComponent\Employee DB.cs Line: 139
Stack Trace:
[IndexOutOfRangeException: EmployeeID] System.Data.ProviderBase.FieldNameLookup.GetOrdina l(String fieldName) +95 System.Data.SqlClient.SqlDataReader.GetOrdinal(Str ing name) +170 System.Data.SqlClient.SqlDataReader.get_Item(Strin g name) +35 DatabaseComponent.EmployeeDB.GetEmployee(Int32 employeeID) in C:\Documents and Settings\Heko\My Documents\Visual Studio 2005\Projects\Heko9Test\DataBaseComponent\Employee DB.cs:139[TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeMethodHandle._InvokeMethodFast(Objec t target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0 System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +358 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29 System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +17 System.Web.UI.WebControls.ObjectDataSourceView.Inv okeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +676 System.Web.UI.WebControls.ObjectDataSourceView.Exe cuteSelect(DataSourceSelectArguments arguments) +2664 System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +84 System.Web.UI.WebControls.DataBoundControl.Perform Select() +153 System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99 System.Web.UI.WebControls.DetailsView.DataBind() +23 System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +92 System.Web.UI.WebControls.DetailsView.EnsureDataBo und() +196 System.Web.UI.WebControls.BaseDataBoundControl.OnP reRender(EventArgs e) +33 System.Web.UI.WebControls.DetailsView.OnPreRender( EventArgs e) +61 System.Web.UI.Control.PreRenderRecursiveInternal() +148 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.Control.PreRenderRecursiveInternal() +233 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4435
---------------------------------------------------------------
i made a breakpoint at the line of
Line 139
EmployeeDetails emp = new EmployeeDetails((int)reader["EmployeeID"], (string)reader["FirstName"],(string)reader["LastName"], (string)reader["TitleOfCourtesy"]);
but i cant findout the problem ,,
thank you for help me anyway
|