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.

The Database Forum


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



Reply
Help about storedProcedure ,,, i hope someone help me
Old 02-13-2009, 07:31 AM Help about storedProcedure ,,, i hope someone help me
Average Talker

Posts: 21
Name: Hesham
Location: Ismailia , EGYPT
Trades: 0
i try to find out the problem by my self but i cant i hope somebody help me

here my storedprocedure

ALTER PROCEDURE GetEmployee
@EmployeeID
Int
AS
SELECT
FirstName,LastName,TitleOfCourtesy
FROM Employees WHERE EmployeeID = @EmployeeID


RETURN


am try to excute it and its gives me this message

Running [dbo].[GetEmployee] ( @EmployeeID = <DEFAULT> ).
Procedure or Function 'GetEmployee' expects parameter '@EmployeeID', which was not supplied.
No rows affected.
(0 row(s) returned)
@RETURN_VALUE =
Finished running [dbo].[GetEmployee].

am try to bind a DetailsView by ObjectDatasource from Class incluse the GetEmployee() Method and this method gives me error on the line i declared the variable that hold the data from the stored procedure thats all if you need more explain tell me ok thanks anyway
blue_way2002 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-13-2009, 08:02 AM Re: Help about storedProcedure ,,, i hope someone help me
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
[dbo].[GetEmployee] ( @EmployeeID = <DEFAULT> )
Your problem is there.
1) You must use the ( and ) only when calling a function, not a stored procedure.
2) You say that the SP should use the default value, but there is none. Give it something to work with!
This should do the trick:
Code:
exec [dbo].[GetEmployee] @EmployeeID = 14
And by the way, a stored procedure doesn't have to return something. You can drop the line that says:
Code:
RETURN
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 02-13-2009 at 08:03 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-13-2009, 10:40 PM Re: Help about storedProcedure ,,, i hope someone help me
Average Talker

Posts: 21
Name: Hesham
Location: Ismailia , EGYPT
Trades: 0
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
blue_way2002 is offline
Reply With Quote
View Public Profile
 
Old 02-14-2009, 02:16 PM Re: Help about storedProcedure ,,, i hope someone help me
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
The error message you have seems to means that there is no "employeeid" column in the resultset you try to parse, but I'm not sure.
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 
I'm a DBA, PHP and Python developer.
The less I use .net the better I feel. I really don't like working with it at all.
But when I have to work with it, it's usually with vb.net and c#.

So, you are out of my league here, sorry.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-20-2009, 06:33 PM Re: Help about storedProcedure ,,, i hope someone help me
Average Talker

Posts: 28
Name: Ben Allen
Trades: 0
Quote:
Originally Posted by tripy View Post
The error message you have seems to means that there is no "employeeid" column in the resultset you try to parse, but I'm not sure.
I agree with Tripy - infact if you look at the Stored Procedure you posted, you're not selecting EmployeeID - change the SP to:

Code:
ALTER PROCEDURE GetEmployee
@EmployeeID Int
AS
SELECT EmployeeID,FirstName,LastName,TitleOfCourtesy 
FROM Employees WHERE EmployeeID = @EmployeeID
That should work, you might want to check Reader.HasRows() to ensure something has been returned in the C# code also. Otherwise you might get an error trying to create the EmployeeDetails object with no data.
ballen is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help about storedProcedure ,,, i hope someone help me
 

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.19426 seconds with 12 queries