开发者

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:

                str开发者_开发百科SQLHost = "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?


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()


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜