11 October, 2010
0 Comments
1 category
If you are using a typed dataset (*.xsd) and you want to set it’s connection string, you can use the ObjectDataSource event OnObjectCreated.
protected void MyObjectDaDataSource_OnObjectCreated(object sender, ObjectDataSourceEventArgs e) { if (e != null && e.ObjectInstance != null) { SqlConnection connection = new SqlConnection("Data Source=SQLServerInstanceName1;
User ID=User1;Password=Password1;Initial Catalog=Database1;"); e.ObjectInstance.GetType().GetProperty("Connection",
BindingFlags.NonPublic | BindingFlags.Instance).SetValue(e.ObjectInstance, connection, null); } }
Tags: ASP .NET
Category: Uncategorized