Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value Cannot be null, Parameter name: dataTable

I am using SQL Database and am calling a stored proc from VB.Net, however when I try and will my DataTable I am getting the error as per the title.

My code is:

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

But when i get to the line sqlda.Fill(dt) I get the error as per the tile.

I have tested these parameters in the stored proc and I get results.

Any ideas on how to stop this?

=========================== 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
like image 202
Simon Price Avatar asked Dec 19 '25 04:12

Simon Price


1 Answers

You have to initialize the DataTable first:

Dim dt As DataTable = New DataTable()
like image 198
Munavvar Husein Avatar answered Dec 21 '25 00:12

Munavvar Husein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!