Search code examples
asp.netxmlsqldatasource

Is it possible to serialize the instance of the SqlDataSource into structured text, such as XML?


I'm developing an in-house ASP.Net application, due to some reason, I've to create dynamic page with dynamic created SqlDataSource(s). So, I'm finding a way to serialize and persist the SqlDataSource instance(s) to structured text(s) (e.g. XML), and later on de-serialize back from the structured text(s), then instantiate the corresponding object(s) of SqlDataSource.

Please kindly advise the simplest way to do that.

Thank you!

William


Solution

  • Simplest way will be to serialize relevant properties (such as Connection String, SelectCommand) - these are any way strings. For de-serializing, just create a new SqlDataSource and set these properties (or pass them via constructor).