Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

.NET Forum


You are currently viewing our .NET Forum as a guest. Please register to participate.
Login



Reply
is anybody can help me to Bind data to Gridview by Objectdatasource
Old 02-09-2009, 10:59 AM is anybody can help me to Bind data to Gridview by Objectdatasource
Average Talker

Posts: 21
Name: Hesham
Location: Ismailia , EGYPT
Trades: 0
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
blue_way2002 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-10-2009, 12:18 PM Re: is anybody can help me to Bind data to Gridview by Objectdatasource
Average Talker

Posts: 21
Name: Hesham
Location: Ismailia , EGYPT
Trades: 0
thanks for no help anyway i solve this problem and i hope if anyone had this logic error then have to check the data source maybe stored procedure not call well or some wrong in syntax but when see this error message i show up right here check your Database and the call of its ok thanks for my self hehehe
blue_way2002 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to is anybody can help me to Bind data to Gridview by Objectdatasource
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20195 seconds with 12 queries