c# - Changing dataset connectionstring at runtime vs2010 -
i found solution must older version vs2010. know how vs2010? know?
http://www.csharpbydesign.com/2008/01/overriding-dataset-settings-co.html
let me explain little more detail.
i have c# generated dataset. how can alter connection string can utilize dataset (identically structured yet differently populated) database? has occur @ runtime not know server or database name @ compile time. using vs2010 , sql server 2008 r2 express
i think there no simple way , cannot alter connection-string programmatically entire dataset
since it's set every tableadapter
.
you need use/create partial class of tableadapter
alter connection-string since connection
property internal
(if dal in different assembly). don't alter designer.cs file since recreated automatically after next alter on designer. create right-click dataset , chose "show code".
for illustration (assuming tableadapter
named producttableadapter
):
namespace windowsformsapplication1.dataset1tableadapters { public partial class producttableadapter { public string connectionstring { { homecoming connection.connectionstring; } set { connection.connectionstring = value; } } } }
now can alter easily:
var producttableadapter = new dataset1tableadapters.producttableadapter(); producttableadapter.connectionstring = someotherconnectionstring;
here's screesnhot of sample dataset , created file dataset1.cs
:
c# sql dataset
No comments:
Post a Comment