我正在使用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)
行时,我会根据瓷砖得到错误。
我在存储过程中测试了这些参数,然后得到了结果。
有关如何制止此事的任何想法?
=========================== edit 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
答案 0 :(得分:6)
您必须首先初始化DataTable:
Dim dt As DataTable = New DataTable()