Posts: 21
Name: Hesham
Location: Ismailia , EGYPT
|
am doing some practice to bind data by ObjectDatasource so i have EmployeeBD.cs and include this method that i retrieve the employees by it
public EmployeeDetails GetEmployee(int employeeID)
{
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("GetEmployee", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@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 = new EmployeeDetails(
(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.
throw new ApplicationException("Data error.");
}
finally
{
con.Close();
}
}
this is the method i need to invoke it with the objectdatasoyrce adapter so this information will retrieve from the stored procedure called Getemployee as you can see ,,,
and here is the HTML code for the objectdata source adapter after u attache the employeeDB class to it and invoke the Getemployee method
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetEmployee"
TypeName="DatabaseComponent.EmployeeDB">
<SelectParameters>
<asp:Parameter Name="employeeID" Type="Int32" />
</SelectParameters>
when am try to run the page its give me this error ,,,,
Server Error in '/Website' Application.
Data error.
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.ApplicationException: Data error.
Source Error:
Line 172: // Replace the error with something less specific.
Line 173: // You could also log the error now.
Line 174: throw new ApplicationException("Data error.");
Line 175: }
Line 176: finally
Source File: c:\Documents and Settings\Heko\Desktop\Pro_ASP_NET_2_0_in_C_2005-2299\Pro ASP.NET 2.0\Chapter09\Website\App_Code\EmployeeDB.cs Line: 174
Stack Trace:
[ApplicationException: Data error.]
DatabaseComponent.EmployeeDB.GetEmployee(Int32 employeeID) in c:\Documents and Settings\Heko\Desktop\Pro_ASP_NET_2_0_in_C_2005-2299\Pro ASP.NET 2.0\Chapter09\Website\App_Code\EmployeeDB.cs:174
[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.Web.UI.WebControls.ObjectDataSourceView.Inv okeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +482
System.Web.UI.WebControls.ObjectDataSourceView.Exe cuteSelect(DataSourceSelectArguments arguments) +1869
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +13
System.Web.UI.WebControls.DataBoundControl.Perform Select() +140
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +68
System.Web.UI.WebControls.GridView.DataBind() +5
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +61
System.Web.UI.WebControls.CompositeDataBoundContro l.CreateChildControls() +67
System.Web.UI.Control.EnsureChildControls() +97
System.Web.UI.Control.PreRenderRecursiveInternal() +50
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Control.PreRenderRecursiveInternal() +171
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5729
and you have to know that i put
|