How to pass null value into store procedure with entity framework?

asp.net-mvc c# entity-framework

Question

I'm using the entityframework with a mvc application. I want to call the store method with a parameter of null values. Occasionally, MerchantID has value, thus I want to pass it as null.

GetValues(int[] TicketID,int? MerchantID,bool IsOpen)
{

//TicketID has values 1123,1122 etc
//MerchantID sometimes null
//IsOpen true/false

  DataTable tbldepartmentid = new DataTable("Departmentid");
             tbldepartmentid.Columns.Add("VALUE", typeof(int));
            foreach (var id in TicketID)
                tbldepartmentid.Rows.Add(id);



 List<GetTroubleTicketDetails_Result> GetTroubleTicketDetails = _getTroubleTicketDetails_Result.ExecuteCustomStoredProc("Tickets.GetDetails", " @GroupID,@MerchantID,@Open",
                 new SqlParameter("GroupID", SqlDbType.Structured) { Value = tbldepartmentid, TypeName = "dbo.tblTVPForCSVINT" }
                 , new SqlParameter("MerchantID", MerchantID)
                 , new SqlParameter("Open", IsOpen)).ToList();
                return GetTroubleTicketDetails;

}

My issue is that if I enter "MerchantID=null," I get the following error.

"The parameterized query '(@GroupID [dbo].[tblTVPForCSVINT] READONLY,@MerchantID nvarchar(' expects the parameter '@MerchantID', which was not supplied."

How can the MerchantID parameter be set to null?

1
8
7/3/2015 7:58:53 AM

Accepted Answer

ZZZ_tmp
18
7/3/2015 8:31:36 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow