0
它進一步指出,過程或函數spAddOrganization
預計但未提供類型「System.ArgumentException」的例外,在System.Data.dll中發生,但在用戶代碼中沒有處理
IEnumerable<OrganizationalDetails> OrganizationalDetails
{
get
{
string connectionString = ConfigurationManager.ConnectionStrings["OnlineDBContext"].ToString();
List<OrganizationalDetails> organization = new List<OrganizationalDetails>();
using (SqlConnection con = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand("spAddOrganization", con);
cmd.CommandType = CommandType.StoredProcedure;`
con.Open();
SqlDataReader myreader = cmd.ExecuteReader();
while(myreader.Read())
{
OrganizationalDetails organize = new OrganizationalDetails();
organize.Organizational_Id = Convert.ToInt32(myreader["Organizational_Id"].ToString());
organize.Organizational_Number = myreader["Organizational_Number"].ToString();
organize.Location = myreader["Location"].ToString();
organize.Organization_Address = myreader["Organizational_Address"].ToString();
organize.TelephoneNo_Org = myreader["TelephoneNo_Org"].ToString();
organize.Organizational_Name = myreader["Organizational_Name"].ToString();`ganizational_Name = myreader["Organizational_Name"].ToString();_Name = myreader["Organizational_Name"].ToString();
organize.Administrator_Name = myreader["Administrator_Name"].ToString();
organization.Add(organize);
}
}
return organization;
}
}
Organizational_Number
參數所存儲的程序如下:
ALTER PROCEDURE [dbo].[spAddOrganization]
@Organizational_Number nvarchar(50),
@Location nvarchar(50),
@Organizational_Address nvarchar(50),
@TelephoneNo_Org nvarchar(50),
@Organizational_Name nvarchar(50),
@Administrator_Name nvarchar(50)
AS
BEGIN
INSERT INTO Organization_Details(Organizational_Number,Location,Organizational_Address,TelephoneNo_Org,Organizational_Name,Administrator_Name)
VALUES(@Organizational_Number,@Location,@Organizational_Address,@TelephoneNo_Org,@Organizational_Name,@Administrator_Name)
END
一切似乎都很完美。我嘗試了谷歌搜索,嘗試但發現不是很容易理解的答案。
的錯誤信息是相當自我explainatory - AddOrganization是插入值,所以它的期待值,「@ Organizational_Number,@位置,@ Organizational_Address,@ TelephoneNo_Org,@ Organizational_Name,@ Administrator_Name「你還沒有提供任何..實際上你似乎認爲它會選擇的東西 - 你必須選擇錯誤的存儲過程 – BugFinder
請格式化您的代碼片斷以可讀的方式和閱讀[如何創建一個最小,完整和可驗證的示例](http://stackoverflow.com/help/mcve)。 –
您的存儲過程需要參數(您沒有提供)並將它們插入到表中。你的代碼試圖打開一個閱讀器,這意味着你的代碼期望用一個select語句調用一個過程。這有點脫節。 – Theo