0

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?

2 Answers 2

5

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()
Sign up to request clarification or add additional context in comments.

4 Comments

Wouldn't it just turn the rest of the line into a comment?
lcarus, that is a comment line. I did remove it, but no luck
@JeffO OP updated his question. He had a ' right after appid=0 and I thought he meant to concatenate the output of dmRow("appid") or something like that he had written initially
Dim dtHost As DataTable = new DataTable() was the answer. Thanks very much lcarus !!!
1
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

1 Comment

sorry... that was a typo on my part in the original posting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.