Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 存储过程,空参数_C#_Sql Server 2008_Stored Procedures_Mvvm - Fatal编程技术网

C# 存储过程,空参数

C# 存储过程,空参数,c#,sql-server-2008,stored-procedures,mvvm,C#,Sql Server 2008,Stored Procedures,Mvvm,我在c、wpf和mvvm中工作,并在SQLServer2008中使用存储过程 我在发送值时遇到问题​​对于执行存储过程的函数,我从一个表单中得到,在这个表单中它可以保留一些字段为空。但是这些是类的对象,那么访问它们的值不应该为null。我留下密码 public IEnumerable<Model.AsuntoModel> GetBusqueda(Model.PrioridadModel prioridad, Model.StatusAsuntoModel status

我在c、wpf和mvvm中工作,并在SQLServer2008中使用存储过程

我在发送值时遇到问题​​对于执行存储过程的函数,我从一个表单中得到,在这个表单中它可以保留一些字段为空。但是这些是类的对象,那么访问它们的值不应该为null。我留下密码

        public IEnumerable<Model.AsuntoModel> GetBusqueda(Model.PrioridadModel prioridad, Model.StatusAsuntoModel statusasunto, Model.DestinatarioModel destinatario, Model.SignatarioModel signatario, DateTime rangofecha, DateTime referenciadocumento)
    {
        ObservableCollection<Model.AsuntoModel> Busqueda = new ObservableCollection<Model.AsuntoModel>();
        using (var entity = new GestorDocumentEntities())
        {

            try 
             {
                 entity.GetAsuntos(prioridad.IdPrioridad, statusasunto.IdStatusAsunto, destinatario.IdDestinatario, signatario.IdSignatario, referenciadocumento).ToList().ForEach(p =>
                 {
                     Busqueda.Add(new Model.AsuntoModel()
                     {
                         IdAsunto = p.IdAsunto,
                         FechaCreacion = (DateTime)p.FechaCreacion,
                         FechaRecibido = (DateTime)p.FechaRecibido,
                         FechaDocumento = (DateTime)p.FechaDocumento,
                         Titulo = p.Titulo,
                         Descripcion = p.Descripcion,
                         Alcance = p.Alcance,
                         IdUbicacion = (long)p.IdUbicacion,
                         Ubicacion = new Model.UbicacionModel()
                         {
                             UbicacionName = p.CAT_UBICACION.UbicacionName
                         },
                         IdInstruccion = (long)p.IdInstruccion,
                         Instruccion = new Model.InstruccionModel()
                         {
                             InstruccionName = p.CAT_INSTRUCCION.InstruccionName
                         },
                         IdPrioridad = (long)p.IdPrioridad,
                         Prioridad = new Model.PrioridadModel()
                         {
                             PrioridadName = p.CAT_PRIORIDAD.PrioridadName
                         },
                         IdStatusAsunto = p.IdStatusAsunto,
                         StatusAsunto = new Model.StatusAsuntoModel()
                         {
                             StatusName = p.CAT_STATUS_ASUNTO.StatusName
                         },
                         FechaVencimiento = p.FechaVencimiento,
                         Folio = p.Folio
                     });
                 }); 

             }
            catch (Exception)
            {
                ;
            }
        }
        return Busqueda;
    }

您的SP可以编码为将NULL PARM视为任意参数

select *
from table
where (table.col = @COL or @COL IS NULL)
and (table.col2 = @COL2 or @COL2 IS NULL)

以下是众多解决方案之一

只需给SQL参数一个默认值,即可使其为空

例如:

@ParamA = null
@ParamB = null
etc..
然后在SQL端进行管理,以查看收到了多少。 这样,如果您不提供任何参数,您的查询将有一个值,在本例中为null。然后,您可以像这样测试它:

IF @ParamA IS NULL
BEGIN
-- You didn't give that param.
END
ELSE
-- You gave a param