我有一個簡單的表,其具有三個字段:SQLEXCEPTION程序預計參數錯誤
ID (int)
FormData (xml)
TimeStamp (DateTime).
我已經創建了一個存儲過程將值插入被成功地使用的表。然而,在我的嘗試中,它正在捕獲一個
System.Data.SqlClient.SqlException:過程或函數'spInsertApplication'需要參數'@formDataDecoded',它沒有提供。
但是,@ formDataDecoded參數正被插入到數據庫中。
任何想法?我不確定該從哪裏出發?
這裏的存儲過程:
ALTER PROCEDURE [dbo].[spInsertApplication]
-- Add the parameters for the stored procedure here
@formDataDecoded xml,
@timestamp DateTime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO Applications (formXML, TimeStamp) VALUES (@formDataDecoded, @timestamp)
END
這裏的C#:
string con = ConfigurationManager.AppSettings["umbracoDbDSN"];
using (SqlConnection connection = new SqlConnection(con))
{
String encodedFormData = HttpUtility.UrlDecode(formData);
SqlCommand command = connection.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "spInsertApplication";
command.Parameters.AddWithValue("@formDataDecoded", encodedFormData);
command.Parameters.AddWithValue("@timestamp", DateTime.Now);
try
{
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception ex)
{
String errorSql = "INSERT INTO ErrorLog(ErrorText) VALUES (@errorText)";
SqlCommand errorCommand = new SqlCommand(errorSql, connection);
errorCommand.Parameters.AddWithValue("@errorText", ex.ToString());
errorCommand.ExecuteNonQuery();
Response.Redirect("/enterprise-superstars/sounds-like-you-are-already-a-star.aspx");
}
finally
{
connection.Close();
}
}
而且我越來越FORMDATA這樣的:
String formData = Request.Form["xmlToVar"];
我傳遞給saveApplicationform方法。
在此先感謝。
編輯
運行在它的SQL Server Profiler跟蹤,它原來的存儲過程被調用兩次。
事情是一個Flash窗體調用特定的頁面,我將不得不讓人看看Flash代碼,看看它是如何發佈,因爲我沒有寫它。
你如何填充你的表?使用'SqlDataAdapter'還是什麼?發佈更多C#代碼 – abatishchev 2011-05-17 14:12:11
您可以包含調用代碼嗎? – oleksii 2011-05-17 14:12:28
@abatishchev已添加c#代碼 – gdp 2011-05-17 14:15:22