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)
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
精彩评论