コード例 #1
0
        private void FixButton_Click(object sender, EventArgs e)
        {
            AppendStatusText(string.Empty);
            foreach (UpdateInfo updateInfo in Updates)
            {
                // This could be better done with a single update statement
                string sqlText =
                    "SELECT " + updateInfo.ColumnName +
                    " FROM " + updateInfo.TableName +
                    " WHERE " + updateInfo.ColumnName + "=@OriginalKey";

                using (var cn = VoteDb.GetOpenConnection())
                {
                    DataTable table   = new DataTable("Updates");
                    var       command = VoteDb.GetCommand(sqlText, cn);
                    VoteDb.AddCommandParameter(command, "OriginalKey", OriginalKeyTextBox.Text);
                    var adapter = VoteDb.GetDataAdapter(command);
                    adapter.Fill(table);

                    AppendStatusText("Table {0}, Column {1}, Found {2}",
                                     updateInfo.TableName, updateInfo.ColumnName, table.Rows.Count);

                    if (table.Rows.Count > 0)
                    {
                        var builder = VoteDb.GetCommandBuilder(adapter);
                        foreach (DataRow row in table.Rows)
                        {
                            row[updateInfo.ColumnName] = NewKeyTextBox.Text;
                        }
                        adapter.Update(table);
                    }
                }
            }
        }