值不能为null,参数名称:dataTable

Sim*_*ice 2 .net vb.net sql-server

我正在使用SQL数据库,并从VB.Net调用存储过程,但是当我尝试并将我的DataTable我按照标题得到错误.

我的代码是:

Dim dt As DataTable
Using sqlConn As New SqlConnection(_connstr)
    Dim sqlcmd As New SqlCommand()
    Dim dateParam = sqlcmd.Parameters.Add("@reportDate", SqlDbType.Date)
    Dim dateParam2 = sqlcmd.Parameters.Add("@reportDateEndRange", SqlDbType.Date)
    'Dim reportType = sqlcmd.Parameters.Add("@reportType", SqlDbType.VarChar)
    Dim companyId = sqlcmd.Parameters.Add("@companyID", SqlDbType.Int)
    dateParam.Value = DateTime.Now.AddDays(-1)
    dateParam2.Value = DateTime.Today
    'reportType.Value = "'IRF', 'TRF'"
    companyId.Value = 1

    sqlcmd.Connection = sqlConn
    sqlcmd.CommandType = CommandType.StoredProcedure
    sqlcmd.CommandText = "dbo.uspSearchRequest"

    Using sqlda As New SqlDataAdapter(sqlcmd)
        sqlda.Fill(dt)
    End Using
End Using
Run Code Online (Sandbox Code Playgroud)

但是当我到达线路时,sqlda.Fill(dt)我会根据磁贴得到错误.

我已经在存储过程中测试了这些参数,我得到了结果.

关于如何制止这个的任何想法?

===========================编辑1

ALTER procedure [dbo].[uspSearchRequest]
@reportDate date,
@reportDateEndRange date,
@companyID int

as
begin

select 
null as [Report Manager],
null as [Report Detail],
null as [Form],
null as [Attachment],
req.OverallStatus as [Result],
req.ReportNumber as [Report Number],
req.ReportDate as [Report Date],
req.FormNumber  as [Form Number],
req.SubmittedTimestamp as [Submit Date],
req.ApplicantContactPerson  as [Applicant] ,
req.Brand  as [Brand],
req.Department  as [Department]
from ias.dbo.request req
where req.ReportDate  between @reportDate and @reportDateEndRange 
and req.RequestCompanyID = @companyID
end 
go
Run Code Online (Sandbox Code Playgroud)

Mun*_*ein 7

您必须首先初始化DataTable:

Dim dt As DataTable = New DataTable()
Run Code Online (Sandbox Code Playgroud)