I'm want to use references for System.Data.SqlServerCe or System.Data.SqlServer depending on if the user have internet connection or not.
How do i this? Can i declare some kind开发者_如何学C of global variable?
I want to do something like this:
if HASINTERNET
using System.Data.SqlServer
else
using System.Data.SqlServerCe
Your best bet there is to just use DbConnection
or IDbConnection
, and write a factory method that creates the appropriate type of connection to return (as the more abstract DbConnection
/ IDbConnection
).
Then it will work for any connection type. Be sure to use the connection's .CreateCommand()
method etc for creating commands.
Your using
is then just using System.Data;
(or using System.Data.Common;
)
re the actual question; not really. You can do that at compile time, with #if
etc - but not at runtime.
精彩评论