Beispiel #1
0
        private void Update_AllDataGrids()
        {
            OleDbConnection thisConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=dictionary.accdb;Persist Security Info=False");


            string sql = "select OriginalField,TranslationField from BasicDictionary order by OriginalField";

            thisAdapter = new OleDbDataAdapter(sql, thisConnection);
            System.Data.DataSet thisDataSet = new System.Data.DataSet();
            thisAdapter.Fill(thisDataSet, "BasicDictionary1");
            DataTable dt = thisDataSet.Tables["BasicDictionary1"];

            this.BasicDicGrid.DataSource = dt;

            BasicDicGrid.EndEdit();


            sql         = "select OriginalField,TranslationField from NewDictionary order by OriginalField";
            thisAdapter = new OleDbDataAdapter(sql, thisConnection);
            thisAdapter.Fill(thisDataSet, "NewDictionary1");
            dt = thisDataSet.Tables["NewDictionary1"];
            this.NewDicGrid.DataSource = dt;

            NewDicGrid.EndEdit();


            sql         = "select OriginalField,TranslationField from UntransDictionary";
            thisAdapter = new OleDbDataAdapter(sql, thisConnection);
            thisAdapter.Fill(thisDataSet, "UnTransDictionary1");
            dt = thisDataSet.Tables["UnTransDictionary1"];
            this.UntransDicGrid.DataSource = dt;

            thisConnection.Close();
            UntransDicGrid.EndEdit();
        }
Beispiel #2
0
        private void BasicDic_Update_Click(object sender, EventArgs e)
        {
            //check empty key
            for (int i = 0; i < BasicDicGrid.Rows.Count - 1; i++)
            {
                if (BasicDicGrid.Rows[i].Cells[0].Value == null || BasicDicGrid.Rows[i].Cells[0].Value.ToString() == "")
                {
                    MessageBox.Show("Empty key");
                    BasicDicGrid.CurrentCell = BasicDicGrid.Rows[i].Cells[1];
                    return;
                }
                else
                {
                    BasicDicGrid.Rows[i].Cells[0].Value = Regex.Replace(BasicDicGrid.Rows[i].Cells[0].Value.ToString(), @"\b\s+\b", " ").Trim(' ');
                }
            }

            BasicDicGrid.EndEdit();
            string          sql            = "select OriginalField,TranslationField from BasicDictionary order by OriginalField";
            OleDbConnection thisConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=dictionary.accdb;Persist Security Info=False");


            OleDbDataAdapter da = new OleDbDataAdapter(sql, thisConnection);

            OleDbCommandBuilder bld = new OleDbCommandBuilder(da);

            thisAdapter.UpdateCommand = bld.GetUpdateCommand();



            DataTable dt = (DataTable)BasicDicGrid.DataSource;

            //  dt.AcceptChanges();

            try
            {
                da.Update(dt);
            }
            catch (OleDbException)
            {
                MessageBox.Show("Duplicate keys");
            }


            thisConnection.Close();
        }