I found this tip is very useful for me in my day to day coding. Sometimes you create a table adapter in dataset in Data layer project, everything works fine but you will start wondering how to make it configurable or how to use the connection string in my web project which is in web.config.
You don’t want to keep changing it and compile it everytime you change the database right?Ok so what you can do is now to open or to add “settings.cs” which is located in your data layer project and then you can paste this piece of code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Linq.Properties
{
internal sealed partial class Settings
{
#region generated stuff
public Settings()
{
// // To add event handlers for saving and changing settings, uncomment the lines below:
//
// this.SettingChanging += this.SettingChangingEventHandler;
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
//
}
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e)
{
// Add code to handle the SettingChangingEvent event here.
}
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e)
{
// Add code to handle the SettingsSaving event here.
}
#endregion
#region ->this override
public override object this[string propertyName]
{
get
{
if (propertyName == "scoutsJamboreeConnectionString")
{
return (System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
}
return base[propertyName];
}
set
{
base[propertyName] = value;
}
}
#endregion
}
}