1
蔭試圖數組傳遞給方法然後用它來存儲過程錯誤傳遞陣列,用於存儲過程查詢
protected void Button1_Click(object sender, EventArgs e)
{
string[] names = new string[3] { "Matt", "Joanne", "Robert" };
string User = "Employee";
mav.AccessType(names,User);
}
方法:
public void AccessType(String[] ARR, String Userty)
{
SysCon.Open();
SqlCommand cmdC = new SqlCommand("sp_AccessTypes", SysCon);
cmdC.CommandType = CommandType.StoredProcedure;
cmdC.Parameters.AddWithValue("@ARRAY", ARR);
cmdC.Parameters.AddWithValue("@USER", Userty);
cmdC.ExecuteNonQuery();
SysCon.Close();
}
STORED PROC
ALTER PROCEDURE [dbo].[sp_AccessType]
-- Add the parameters for the stored procedure here
@ARRAY AccessType1 Readonly,
@USER nvarchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO tbl_samplednd1(UserType,parameter1) SELECT * FROM @ARRAY
END
它給出了一個錯誤:
No mapping exists from object type System.String[] to a known managed provider native type.
如何解決?謝謝
的
UserType
和parameter1
列可你至少兩排告訴我們SQL服務器上的AccessType1的父類型? –您不能將數組作爲SQL Server的參數傳遞,因爲它不支持數組。 –
我使用用戶定義的表類型。這是** AccessType1 ** – EnzoZow