public partial class StateDisclaimer : UserControl
{
private Database db;
private DataSet ds;
private DbCommand cmd;
private string strConfigParameters;
public StateDisclaimer()
{
InitializeComponent();
}
private void StateDisclaimer_Load(object sender, EventArgs e)
{
LoadDataGrid();
}
private void LoadDataGrid()
{
try
{
// Create the Database
db = DatabaseFactory.CreateDatabase("dbConnection");
// Retrieve the initial DataSet
ds = new DataSet();
cmd = db.GetStoredProcCommand("sp_getMiniMirandaInfo");
strConfigParameters = "ConfigParameters";
db.LoadDataSet(cmd, ds, strConfigParameters);
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.Columns[0].Visible = false;
dataGridView1.Columns[1].ReadOnly = true;
dataGridView1.Sort(dataGridView1.Columns[1], ListSortDirection.Ascending);
dataGridView1.AutoResizeColumns();
}
catch (DbException ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btnApply_Click(object sender, EventArgs e)
{
if (ds.HasChanges())
{
DbCommand updateCommand = db.GetStoredProcCommand("sp_UpdateConfigParametersDataValue");
db.AddInParameter(updateCommand, "Category", DbType.String, "Category", DataRowVersion.Current);
db.AddInParameter(updateCommand, "KeyValue", DbType.String, "KeyValue", DataRowVersion.Current);
db.AddInParameter(updateCommand, "DataValue", DbType.String, "DataValue", DataRowVersion.Current);
int rowsAffected = db.UpdateDataSet(ds, "ConfigParameters", null, updateCommand, null, UpdateBehavior.Standard);
MessageBox.Show(rowsAffected.ToString());
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
if (ds.HasChanges())
{
try
{
ds.RejectChanges();
dataGridView1.Refresh();
}
catch (DbException ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
Thursday, June 08, 2006
Updating a Database Using a DataSet With EntLib 2.0
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment