Frank
Frank

Reputation: 2045

SQL Datatable error "Value cannot be null."

I am executing a sql query, and I am getting an error Value cannot be null. Parameter name: dataTable

Code:

                strSQLHost = "select HostBase.AppName from HostBase where HostBase.appid=0" 
                Dim dtHost As DataTable
                Dim daHost As SqlDataAdapter = New SqlDataAdapter(strSQLHost, conn)
                daHost.Fill(dtHost)

The error occurs at the daHost.Fill(dtHost)
When I run this query in SQL Enterprise manager, I get a value of 'None'. It's a valid value, not a null value.

How can I resolve this?

Upvotes: 0

Views: 3097

Answers (2)

Icarus
Icarus

Reputation: 63970

remove the last ' on your statement

I think it should read like this:

strSQLHost = "select Host.AppName from HostBase where HostBase.appid=0"

And instantiate your DataTable before passing it in:

Dim dtHost As DataTable = new DataTable()

Upvotes: 5

JeffO
JeffO

Reputation: 8053

select Host.AppName from HostBase where HostBase.appid=0

Seems like you're mixing table names when you only refer to one table: HostBase. You can't use table: Host in this query without including it in some sort of join (Even if it turned into a Cartesian Product) This is the change.

select HostBase.AppName from HostBase where HostBase.appid=0

Put a break and see the exact value of the string variable: strSQLHost

Upvotes: 1

Related Questions