Zdravím vo spolok, potýkam sa z jedným problémom. Pre uloženie a aktualizáciu hodnôt do databázy používam uloženú procedúru. Po získaní a zadaní všetkých potrebných hodnôt sa zápis a aktualizácia do SQL databázy uskutoční v poriadku, ale aplikácia aj napriek tomu zobrazí nasledujúcu chybovú hlášku: Server Error in '/' Application.Procedure or function 'BondMarketers_InsertPayment' expects parameter '@UserID', which was not supplied. Exception Details: System.Data.SqlClient.SqlException: Procedure or function 'BondMarketers_InsertPayment' expects parameter '@UserID', which was not supplied. Stack Trace: [SqlException (0x80131904): Procedure or function 'BondMarketers_InsertPayment' expects parameter '@UserID', which was not supplied.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2091750 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5103168 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +260 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2294 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +215 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +987 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +178 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137 System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +394 System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +407 System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +89 System.Web.UI.WebControls.DetailsView.HandleInsert(String commandArg, Boolean causesValidation) +379 System.Web.UI.WebControls.DetailsView.InsertItem(Boolean causesValidation) +60 RadBond.Pages.User.PayProfit.InsertBtnClick(Object sender, EventArgs e) in C:\Users\Patrik\documents\visual studio 2010\Projects\RadBond\RadBond\Pages\User\PayProfit.aspx.cs:107 Telerik.Web.UI.RadButton.OnClick(ButtonClickEventArgs e) +96 Telerik.Web.UI.RadButton.RaisePostBackEvent(String eventArgument) +229 Telerik.Web.UI.RadButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563 Pri googlení som našiel niekoľko rád a postupov, ale ani jeden nepriniesol ten správny výsledok. Uloženú procedúru volám nasledujúcim spôsobom:
public void InsertBtnClick(object sender, EventArgs e)
{
DetailView1.InsertItem(true);
}
public void DetailView1ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
MembershipUser user = Membership.GetUser();
Guid userID = (Guid)user.ProviderUserKey;
DropDownList processorDdl = DetailView1.FindControl("processorDDL") as DropDownList;
RadNumericTextBox payBox = DetailView1.FindControl("PayAmountBox") as RadNumericTextBox;
GridDataItem item = (GridDataItem)payGrid.SelectedItems[0];
string depositSelected = item["deposit_id"].Text;
int depositID = Convert.ToInt32(depositSelected);
decimal payAmount = Convert.ToDecimal(payBox.Value);
if (DetailView1.CurrentMode == DetailsViewMode.Insert)
{
SqlConnection con = new SqlConnection(BondConfiguration.DbConnectionString);
SqlCommand cmd = new SqlCommand("BondMarketers_InsertPayment", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
con.Open();
System.Data.SqlClient.SqlParameter newHistoryID = new System.Data.SqlClient.SqlParameter("@PK_HistoryID", SqlDbType.Int);
newHistoryID.Direction = ParameterDirection.Output;
cmd.Parameters.Add(newHistoryID);
cmd.Parameters.Add("@UserID", SqlDbType.UniqueIdentifier);
cmd.Parameters["@UserID"].Value = (object)userID ?? DBNull.Value;
cmd.Parameters.Add("@DepositID", SqlDbType.Int);
cmd.Parameters["@DepositID"].Value = (object)depositID ?? DBNull.Value;
cmd.Parameters.Add("@PayProcessor", SqlDbType.NVarChar);
cmd.Parameters["@PayProcessor"].Value = processorDdl.SelectedValue.ToString();
cmd.Parameters.Add("@Pay_Amount", SqlDbType.Decimal);
cmd.Parameters["@Pay_Amount"].Value = (object)payAmount ?? DBNull.Value;
cmd.ExecuteNonQuery();
con.Close();
}
}
Kód procedury je nasledovný:
CREATE PROCEDURE [dbo].[BondMarketers_InsertPayment]
-- Add the parameters for the stored procedure here
@DepositID int = null,
@Pay_Amount numeric (20,5) = null,
@PayProcessor nvarchar(30) = null,
@UserID uniqueidentifier,
@PK_HistoryID int OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
DECLARE @Status nvarchar (10)
SET @Status = 'Pending'
DECLARE @Pay_Date datetime2 (0)
SET @Pay_Date = GETDATE()
INSERT INTO bondAdmin.Payment (UserID, PayAmount, PayDate, Status, DepositID, PayProcessor) VALUES (@UserID, @Pay_Amount, @Pay_Date, @Status, @DepositID, @PayProcessor)
SELECT @PK_HistoryID = @@IDENTITY
UPDATE dbo.history SET pay_amount = pay_amount + @Pay_Amount, pay_id = @PK_HistoryID WHERE deposit_id = @DepositID
RETURN(1)
END
Ďakujem za každú radu.
|