0
我正在使用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
但是,當我站上罰球線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
大概推測'dt'爲null(Nothing)。我們不知道你在哪裏創建數據表... –
我的猜測是存儲過程需要其他一些你沒有指定的值,那麼默認情況下數據庫不允許爲null?你能否展示sproc的簽名? –
在sqlda.Fill(dt)中放置一個斷點並檢查dt是否Nothing – Tuco