Exemple #1
0
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     if (isNewRow)
     {
         DataRow newRow = dsSample.Tables["Book"].NewRow();
         newRow["BookCode"]      = txtBookCode.Text;
         newRow["Title"]         = txtTitle.Text;
         newRow["PublisherCode"] = txtPubCode.Text;
         newRow["Type"]          = txtType.Text;
         newRow["Price"]         = Convert.ToDouble(txtPrice.Text);
         newRow["Paperback"]     = chkPaperback.IsChecked;
         dsSample.Tables["Book"].Rows.Add(newRow);
         rowIndex = dsSample.Tables["Book"].Rows.Count - 1;
     }
     else
     {
         dsSample.Tables["Book"].Rows[rowIndex].BeginEdit();
         dsSample.Tables["Book"].Rows[rowIndex]["BookCode"]      = txtBookCode.Text;
         dsSample.Tables["Book"].Rows[rowIndex]["Title"]         = txtTitle.Text;
         dsSample.Tables["Book"].Rows[rowIndex]["PublisherCode"] = txtPubCode.Text;
         dsSample.Tables["Book"].Rows[rowIndex]["Type"]          = txtType.Text;
         dsSample.Tables["Book"].Rows[rowIndex]["Price"]         = Convert.ToDouble(txtPrice.Text);
         dsSample.Tables["Book"].Rows[rowIndex]["Paperback"]     = chkPaperback.IsChecked;;
         dsSample.Tables["Book"].Rows[rowIndex].EndEdit();
     }
     daBooks.UpdateCommand = builder.GetUpdateCommand();
     daBooks.Update(dsSample, "Book");
     viewMode();
 }
Exemple #2
0
        /// <summary>
        /// Pre-Condition:  The parameters will be in the order of passing the dataset,
        ///                 and the string table name.
        /// Post-Condition: The update dataset will be persisted in the database.
        /// Description:    This method will update the database based on the updated
        ///                 records in the dataset for a given table.
        /// </summary>
        /// <param name="pDataSet">The dataset that contains the updated records.</param>
        /// <param name="pStrTableName">The table name that will be updated in the
        ///                             database.</param>
        public void SaveData(DataSet pDataSet, string pStrTableName)
        {
            string strQuery = "SELECT * FROM " + pStrTableName;

            OleDbDataAdapter dbDA = new OleDbDataAdapter(strQuery, _dbConn);

            try
            {
                // setup Command Builders
                OleDbCommandBuilder dbBLD = new OleDbCommandBuilder(dbDA);
                dbDA.InsertCommand = dbBLD.GetInsertCommand();
                dbDA.UpdateCommand = dbBLD.GetUpdateCommand();
                dbDA.DeleteCommand = dbBLD.GetDeleteCommand();

                // subscribe to the OleDbRowUpdateEventHandler
                dbDA.RowUpdated += new OleDbRowUpdatedEventHandler(OnRowUpdated);

                _dbConn.Open();
                dbDA.Update(pDataSet, pStrTableName);
                pDataSet.Tables[pStrTableName].AcceptChanges();
                _dbConn.Close();
                pStrTableName = null;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            finally
            {
                _dbConn.Close();
            }
        }
Exemple #3
0
        // <Snippet1>
        static private DataSet CreateCommandAndUpdate(
            string connectionString,
            string queryString)
        {
            DataSet dataSet = new DataSet();

            using (OleDbConnection connection =
                       new OleDbConnection(connectionString))
            {
                connection.Open();
                OleDbDataAdapter adapter =
                    new OleDbDataAdapter();
                adapter.SelectCommand =
                    new OleDbCommand(queryString, connection);
                OleDbCommandBuilder builder =
                    new OleDbCommandBuilder(adapter);

                adapter.Fill(dataSet);

                // Code to modify data in the DataSet here.

                // Without the OleDbCommandBuilder, this line would fail.
                adapter.UpdateCommand = builder.GetUpdateCommand();
                adapter.Update(dataSet);
            }
            return(dataSet);
        }
Exemple #4
0
        public void Upload_table(DataTable D_table, string table_str, Dictionary <string, string> dic_where)
        {
            string select_str;

            //create select statment to use in build
            select_str = dic_to_string_Read(dic_where, table_str, "*");
            //start build commands
            OleDbConnection     con     = new OleDbConnection(connectionStringW);
            OleDbDataAdapter    da      = new OleDbDataAdapter(select_str, con);
            OleDbCommandBuilder builder = new OleDbCommandBuilder(da);

            builder.QuotePrefix = "[";
            builder.QuoteSuffix = "]";
            da.UpdateCommand    = builder.GetUpdateCommand();
            da.InsertCommand    = builder.GetInsertCommand();
            //builder.GetDeleteCommand();
            //builder.GetInsertCommand();
            //builder.GetUpdateCommand();
            //think of how to force update statment to update specific colomns only
            try
            {
                da.Update(D_table);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
                con.Close();
                throw;
            }
        }
Exemple #5
0
        // Disconnected
        //פעולה המעדכנת את הדטהבייס בהתאם לדטהסט
        public static void Update(DataSet ds, string com, string name)
        {
            OleDbConnection cn      = new OleDbConnection(Connect.GetConnectionString());
            OleDbCommand    command = new OleDbCommand();

            command.Connection  = cn;
            command.CommandText = com;

            OleDbDataAdapter adapter = new OleDbDataAdapter(command);

            OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);

            adapter.InsertCommand = builder.GetInsertCommand();
            adapter.DeleteCommand = builder.GetDeleteCommand();
            adapter.UpdateCommand = builder.GetUpdateCommand();
            try
            {
                cn.Open();
                adapter.Update(ds, name);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                cn.Close();
            }
        }
        public bool TryFillAndUpdate(GasMeter gasValues)
        {
            var select = "SELECT * FROM GAS_VALUES";

            _adapter.SelectCommand = new OleDbCommand(select, MyConnection);
            try
            {
                _adapter.Fill(_currentTable);
                var tmpGasValues = new object[5];
                _keyCounter     = GetLastKey();
                tmpGasValues[0] = ++_keyCounter;
                tmpGasValues[1] = gasValues.Number;
                tmpGasValues[2] = DateTime.Now;
                tmpGasValues[3] = gasValues.Hydrogen;
                tmpGasValues[4] = gasValues.Oxygen;
                _currentTable.Rows.Add(tmpGasValues);
                _adapter.UpdateCommand = _builder.GetUpdateCommand();
                _adapter.Update(_currentTable);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
        private int SaveData(string SQL, DataTable dt)
        {
            int result;

            if (dt == null)
            {
                return(-1);
            }
            if (dt.DataSet != null && !dt.DataSet.HasChanges())
            {
                Helper.ShowMessage(true);
            }

            OleDbDataAdapter    da = GetDataAdapter(SQL);
            OleDbCommandBuilder cb = GetCommandBuilder(da);

            OpenConnection();
            da.InsertCommand = cb.GetInsertCommand();
            da.UpdateCommand = cb.GetUpdateCommand();
            da.DeleteCommand = cb.GetDeleteCommand();

            result = da.Update(dt);
            CloseConnection();
            return(result);
        }
Exemple #8
0
        public Form1()
        {
            InitializeComponent();

            adapter_grupa   = new OleDbDataAdapter("select * from Grupa", @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\petar\Documents\SKOLA\Treca godina\TVP\Projekat_septembar\Prodavnica\Prodavnica.mdb");
            adapter_artikal = new OleDbDataAdapter("select * from Artikal", @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\petar\Documents\SKOLA\Treca godina\TVP\Projekat_septembar\Prodavnica\Prodavnica.mdb");
            adapter_racun   = new OleDbDataAdapter("select * from Racun", @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\petar\Documents\SKOLA\Treca godina\TVP\Projekat_septembar\Prodavnica\Prodavnica.mdb");

            OleDbCommandBuilder cmdBuild = new OleDbCommandBuilder(adapter_artikal);

            adapter_artikal.InsertCommand = cmdBuild.GetInsertCommand();
            adapter_artikal.UpdateCommand = cmdBuild.GetUpdateCommand();
            adapter_artikal.DeleteCommand = cmdBuild.GetDeleteCommand();

            cmdBuild = new OleDbCommandBuilder(adapter_racun);
            adapter_racun.InsertCommand = cmdBuild.GetInsertCommand();
            adapter_racun.UpdateCommand = cmdBuild.GetUpdateCommand();
            adapter_racun.DeleteCommand = cmdBuild.GetDeleteCommand();

            OleDbDataAdapter da = new OleDbDataAdapter("select * from Grupa ;select * from Artikal; select * from Racun", @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\petar\Documents\SKOLA\Treca godina\TVP\Projekat_septembar\Prodavnica\Prodavnica.mdb");

            ds = new DataSet();

            adapter_grupa.Fill(ds, "Grupa");
            adapter_artikal.Fill(ds, "Artikal");
            adapter_racun.Fill(ds, "Racun");

            cbKategorija.DataSource    = ds.Tables["Grupa"];
            cbKategorija.DisplayMember = "Naziv";
            cbKategorija.ValueMember   = "id_grupa";
            PopuniRacun();
        }
Exemple #9
0
        public void modify(Form3 f, int found)
        {
            OleDbConnection conn    = new OleDbConnection();
            String          s       = System.Environment.CurrentDirectory;
            string          connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";

            connStr += @s + @"//StudentManager.mdb";
            // Console.WriteLine("当前连接字符串为:\n" + connStr + "\n");
            conn.ConnectionString = connStr;
            string              strSelectQuery = "select * from students";
            OleDbCommand        cmd            = new OleDbCommand(strSelectQuery, conn);
            OleDbDataAdapter    da             = new OleDbDataAdapter();
            OleDbCommandBuilder cb             = new OleDbCommandBuilder(da);

            da.SelectCommand = cmd;
            da.UpdateCommand = cb.GetUpdateCommand();


            DataSet result = new DataSet();

            da.Fill(result, "students");
            result.Tables[0].Rows[found]["Name"]    = f.textBox1.Text;
            result.Tables[0].Rows[found]["ID"]      = f.textBox2.Text;
            result.Tables[0].Rows[found]["Sex"]     = f.textBox3.Text;
            result.Tables[0].Rows[found]["Class"]   = f.textBox4.Text;
            result.Tables[0].Rows[found]["Email"]   = f.textBox5.Text;
            result.Tables[0].Rows[found]["Chinese"] = f.textBox6.Text;
            result.Tables[0].Rows[found]["Math"]    = f.textBox7.Text;
            result.Tables[0].Rows[found]["English"] = f.textBox8.Text;
            da.Update(result, "students");
            conn.Close();
        }
        /// <summary>
        /// Queries the database and populates a dataset.
        /// </summary>
        private void RetrieveDataFromTheDatabase()
        {
            try
            {
                string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='AMDatabase.mdb'";

                this.connection = new OleDbConnection();
                this.connection.ConnectionString = connectionString;
                this.connection.Open();

                OleDbCommand selectCommand = new OleDbCommand();
                selectCommand.CommandText = "SELECT * FROM VehicleStock";
                selectCommand.Connection  = this.connection;

                this.adapter = new OleDbDataAdapter();
                this.adapter.SelectCommand = selectCommand;

                OleDbCommandBuilder builder = new OleDbCommandBuilder();
                builder.DataAdapter = this.adapter;

                this.adapter.UpdateCommand = builder.GetUpdateCommand();
                this.adapter.DeleteCommand = builder.GetDeleteCommand();
                this.adapter.InsertCommand = builder.GetInsertCommand();

                this.dataset = new DataSet();

                this.adapter.Fill(this.dataset, "VehicleStock");
            }
            catch (Exception e)
            {
                this.connection.Close();
                this.connection.Dispose();
            }
        }
Exemple #11
0
        private void button2_Click(object sender, EventArgs e)
        {
            dataGridView1.EndEdit();
            姓名.Text       = myDataSet.Tables[0].Rows[dataGridView1.CurrentRow.Index][0].ToString(); //显示第1行第1列的一个值
            密码.Text       = myDataSet.Tables[0].Rows[dataGridView1.CurrentRow.Index][1].ToString(); //显示第1行第2列的一个值
            部职别.Text      = myDataSet.Tables[0].Rows[dataGridView1.CurrentRow.Index][2].ToString(); //显示第1行第3列的一个值
            textBox4.Text = myDataSet.Tables[0].Rows[dataGridView1.CurrentRow.Index][3].ToString(); //显示第1行第4列的一个值
            string              sql = "select * from dlxxb";
            OleDbDataAdapter    da  = new OleDbDataAdapter(sql, myConnection);
            OleDbCommandBuilder bld = new OleDbCommandBuilder(da);

            da.UpdateCommand = bld.GetUpdateCommand();
            //把DataGridView赋值给dataTable。(DataTable)的意思是类型转换,前提是后面紧跟着的东西要能转换成dataTable类型
            DataTable dt = (DataTable)dataGridView1.DataSource;

            da.Update(dt);
            dt.AcceptChanges();

            string           strData    = "SELECT * from dlxxb";
            OleDbDataAdapter myData     = new OleDbDataAdapter(strData, myConnection);
            DataSet          myDataSet1 = new DataSet();

            myData.Fill(myDataSet1, "dlxxb");
            dataGridView1.DataSource = myDataSet1.Tables["dlxxb"];
        }
Exemple #12
0
        /// <summary>
        /// Updates the data source with any changes made to the dataset
        /// </summary>
        /// <param name="passedDataset">The dataset that contains the changes</param>
        /// <example>To store any changes made to the dataset you simply need to pass the dataset to the method. Any entries that are
        /// flagged as having been changed will be committed to the datasource (this includes, additions, edits and deletions)
        /// <code>
        ///  //Your code to update the dataset
        ///  myDataHandler.UpdateDataset(myDataset);
        /// </code>
        /// Note - the dataset being updated must be the one created from this particular instance of the datahandler - trying to pass a
        /// dataset not generated by the specific instance of the class will result in a data exception
        /// </example>
        public void UpdateDataset(DataSet passedDataset)
        {
            OleDbCommandBuilder builder = new OleDbCommandBuilder(m_localAdapter);

            m_localAdapter.UpdateCommand = builder.GetUpdateCommand();
            m_localAdapter.Update(passedDataset, passedDataset.Tables[0].TableName);
        }
Exemple #13
0
        // Otvara tablicu Odgovori iz baze podataka Ankete
        public DataTable OpenOdgovori(int id)
        {
            // create the adapter and fill the DataSet
            String    sql        = "SELECT RBR,ODGOVOR,GLASOVI,ID_ANKETE,ID_ODGOVORA FROM ODGOVORI WHERE ID_ANKETE=" + id.ToString() + " ORDER BY RBR";
            DataTable dtOdgovori = null;

            try
            {
                adOdgovori = new OleDbDataAdapter();
                adOdgovori.SelectCommand = new OleDbCommand(sql, conn);
                OleDbCommandBuilder cb = new OleDbCommandBuilder(adOdgovori);
                openDB();
                dsOdgovori = new DataSet("ODGOVORI");
                adOdgovori.Fill(dsOdgovori, "ODGOVORI");

                adOdgovori.UpdateCommand = cb.GetUpdateCommand();
                adOdgovori.InsertCommand = cb.GetInsertCommand();

                dtOdgovori = dsOdgovori.Tables[0];

                bindOdgovori            = new BindingSource();
                bindOdgovori.DataSource = dtOdgovori;

                closeDB();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); };

            return(dtOdgovori);
        }
Exemple #14
0
        //void CopySqlTable(string name,SqlConnection sourceConn,SqlConnection destConn)
        //{
        //    Message("拷貝" + name);
        //    DataTable table = new DataTable(name);
        //    string SelectStr = "Select * From " + name;
        //    var sourceAdapter = new SqlDataAdapter(SelectStr, sourceConn);
        //    try
        //    {
        //        int sourceNo = sourceAdapter.Fill(table);
        //        foreach (DataRow row in table.Rows) row.SetAdded();
        //        var destAdapter = new SqlDataAdapter(SelectStr, destConn);
        //        var builder = new SqlCommandBuilder(destAdapter);
        //        builder.QuotePrefix = "[";    // 因為有些ColumnName是保留字,如Password
        //        builder.QuoteSuffix = "]";
        //        destAdapter.UpdateCommand = builder.GetUpdateCommand();
        //        destAdapter.InsertCommand = builder.GetInsertCommand();
        //        destAdapter.DeleteCommand = builder.GetDeleteCommand();
        //        int no = destAdapter.Update(table);
        //        MessageBox.Show(name + "來源共" + sourceNo.ToString() + "筆,寫出成功" + no.ToString() + "筆");
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show("寫出[" + name + "]時出錯:" + ex.Message);
        //    }
        //}

        void CopyOldDbTable(string name, OleDbConnection sourceConn, OleDbConnection destConn)
        {
            Message("拷貝" + name);
            DataTable table         = new DataTable(name);
            string    SelectStr     = "Select * From " + name;
            var       sourceAdapter = new OleDbDataAdapter(SelectStr, sourceConn);

            try
            {
                int sourceNo = sourceAdapter.Fill(table);
                foreach (DataRow row in table.Rows)
                {
                    row.SetAdded();
                }
                var destAdapter = new OleDbDataAdapter(SelectStr, destConn);
                var builder     = new OleDbCommandBuilder(destAdapter);
                builder.QuotePrefix       = "["; // 因為有些ColumnName是保留字,如Password
                builder.QuoteSuffix       = "]";
                destAdapter.UpdateCommand = builder.GetUpdateCommand();
                destAdapter.InsertCommand = builder.GetInsertCommand();
                destAdapter.DeleteCommand = builder.GetDeleteCommand();
                int no = destAdapter.Update(table);
                MessageBox.Show(name + "來源共" + sourceNo.ToString() + "筆,寫出成功" + no.ToString() + "筆");
            }
            catch (Exception ex)
            {
                MessageBox.Show("寫出[" + name + "]時出錯:" + ex.Message);
            }
        }
Exemple #15
0
        //-----------------------------
        //DataGridView에 데이터 채우기
        //-----------------------------
        private void LoadData()
        {
            try
            {
                string sql = "select * from addrbook";

                LocalConn = Common_DB.DBConnection();
                LocalConn.Open();
                adapter = new OleDbDataAdapter(sql, LocalConn);
                cb      = new OleDbCommandBuilder(adapter);

                adapter.DeleteCommand = cb.GetDeleteCommand();
                adapter.InsertCommand = cb.GetInsertCommand();
                adapter.UpdateCommand = cb.GetUpdateCommand();

                ds = new DataSet();
                adapter.Fill(ds, "ADDRBOOK");

                dataGrid1.DataSource = ds.Tables["ADDRBOOK"];
            }
            catch (Exception e1)
            {
                MessageBox.Show("주소록 저장 오류~" + e1.ToString());
                Log.WriteLine("FrmDataGridView", e1.ToString());
            }
            finally
            {
                LocalConn.Close();
            }
        }
Exemple #16
0
 public void updateDatabase()
 {
     using (OleDbConnection connec = new OleDbConnection())
     {
         OleDbCommand commande = new OleDbCommand();
         try
         {
             connec.ConnectionString = chcon;
             connec.Open();
             using (OleDbDataAdapter da =
                        new OleDbDataAdapter())
             {
                 da.SelectCommand = new OleDbCommand("Select * from Utilisateurs", connec);
                 OleDbCommandBuilder builder = new OleDbCommandBuilder(da);
                 da.UpdateCommand = builder.GetUpdateCommand();
                 da.Update(dsEsp, "Utilisateurs");
             }
         }
         catch (Exception x)
         {
             MessageBox.Show(x.Message);
         }
         finally
         {
             connec.Close();
         }
     }
 }
Exemple #17
0
 public static bool AzurirajPodatke(DataSet ds)
 {
     try
     {
         try
         {
             OleDbDataAdapter    da = new OleDbDataAdapter("select * from Artikal", konekcijaString);
             OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
             da.UpdateCommand = cb.GetUpdateCommand();
             da.Update(ds.Tables["Artikal"]);
         }
         catch
         {
             MessageBox.Show("Ukoliko brišete neki zapis ponovite čuvanje još jednom");
         }
         OleDbDataAdapter    da2 = new OleDbDataAdapter("select * from Grupisanje", konekcijaString);
         OleDbCommandBuilder cb2 = new OleDbCommandBuilder(da2);
         da2.UpdateCommand = cb2.GetUpdateCommand();
         da2.Update(ds.Tables["Grupisanje"]);
         return(true);
     }
     catch (Exception e)
     {
         MessageBox.Show("Doslo je do greške" + Environment.NewLine + e.Message);
         return(false);
     }
 }
Exemple #18
0
        public static void InsertClientProtocol(string[] str, string tablename)
        {
            string              selectCommandText   = "SELECT * FROM " + tablename;
            OleDbDataAdapter    oleDbDataAdapter    = new OleDbDataAdapter(selectCommandText, AccessFunction.dbConnection);
            OleDbCommandBuilder oleDbCommandBuilder = new OleDbCommandBuilder(oleDbDataAdapter);
            DataSet             dataSet             = new DataSet();

            oleDbDataAdapter.Fill(dataSet);
            OleDbCommandBuilder oleDbCommandBuilder2 = new OleDbCommandBuilder(oleDbDataAdapter);

            oleDbDataAdapter.UpdateCommand = oleDbCommandBuilder2.GetUpdateCommand();
            int count = dataSet.Tables[0].Columns.Count;

            if (tablename != "Table_room")
            {
                count = count - 1;
            }
            DataRow dataRow = dataSet.Tables[0].NewRow();

            for (int i = 0; i < count; i++)
            {
                dataRow[i] = str[i];
            }
            dataSet.Tables[0].Rows.Add(dataRow);
            oleDbDataAdapter.Update(dataSet);
        }
        /// <summary>
        /// Initializes an instance of VehicelData form.
        /// </summary>
        public VehicelData()
        {
            InitializeComponent();

            //Construct an instance of a connection object
            OleDbConnection oleDbConnection = new OleDbConnection();

            //Setup the ConnectionString
            oleDbConnection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=AMDatabase.mdb";

            //Open the database file
            oleDbConnection.Open();

            //Selection query
            string SqlQuery = "SELECT * FROM VehicleStock";

            //Construct an instance of a command object
            //SqlQuery is the selection
            //oleDbConnection reference to the connection
            OleDbCommand dbCommand = new OleDbCommand(SqlQuery, oleDbConnection);

            //Create an data adapter object
            _dataAdapter = new OleDbDataAdapter();

            //Set the data adapter object's select command to the command object
            _dataAdapter.SelectCommand = dbCommand;

            //Create an data set object
            _dataSet = new DataSet();

            //Using the data adapter object, fill the data set
            //"VehicleStock" is the table name
            _dataAdapter.Fill(_dataSet, "VehicleStock");


            //Create the binding source object
            _bindingSource = new BindingSource();

            //Create the command builder object
            OleDbCommandBuilder oleDbCommandBuilder = new OleDbCommandBuilder();

            //Set the command builder object's data adapter to _dataAdapter
            oleDbCommandBuilder.DataAdapter = _dataAdapter;

            //Use command builder to get required SQL
            _dataAdapter.UpdateCommand = oleDbCommandBuilder.GetUpdateCommand();
            _dataAdapter.InsertCommand = oleDbCommandBuilder.GetInsertCommand();
            _dataAdapter.DeleteCommand = oleDbCommandBuilder.GetDeleteCommand();

            //Resolve the primary key conflict when Adding and Deleting new row
            oleDbCommandBuilder.ConflictOption = ConflictOption.OverwriteChanges;

            //EventHandlers
            _dataAdapter.RowUpdated         += new OleDbRowUpdatedEventHandler(dataAdapter_RowUpdated);
            dgvVehicelData.SelectionChanged += new EventHandler(dgvVehicelData_SelectionChanged);
            dgvVehicelData.CellValueChanged += new DataGridViewCellEventHandler(dgvVehicelData_CellValueChanged);
            this.FormClosing += FormClosingEvent;
            mnuClose.Click   += closeToolStripMenuItem_Click;
            this.Load        += new EventHandler(Form_load);
        }
        //public bool UpdateDbData(string command, DataSet ds)
        //{
        //    if (UpdateDbData(ds.Tables[0], "SystemOption") >= 0)
        //        return true;
        //    else
        //        return false;
        //}

        public bool UpdateDbData(string commandText, DataTable table)
        {
            int affect = -1;

            try
            {
                OleDbConnection connection = new OleDbConnection(Url);
                using (connection)
                {
                    // Create the select command.
                    OleDbCommand command = new OleDbCommand(commandText, connection);
                    // Create the DbDataAdapter.
                    OleDbDataAdapter adapter = new OleDbDataAdapter(command);
                    // Create the DbCommandBuilder.
                    OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
                    builder.RefreshSchema();
                    // Get the insert, update and delete commands.
                    adapter.InsertCommand = builder.GetInsertCommand();
                    adapter.UpdateCommand = builder.GetUpdateCommand();
                    adapter.DeleteCommand = builder.GetDeleteCommand();
                    var dd = table.GetChanges();
                    affect = adapter.Update(table);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(affect > 0 ? true : false);
        }
Exemple #21
0
        public void Update(string strSelectSQL, DataTable objTable)
        {
            OleDbDataAdapter    adapter1;
            OleDbCommandBuilder builder1;

            if (!this.m_bIsInTransaction)
            {
                OleDbCommand command1 = new OleDbCommand(strSelectSQL, this.m_objConn);
                if (this.m_Timeout >= 30)
                {
                    command1.CommandTimeout = this.m_Timeout;
                }
                adapter1 = new OleDbDataAdapter(command1);
                builder1 = new OleDbCommandBuilder(adapter1);
                adapter1.InsertCommand = builder1.GetInsertCommand();
                adapter1.DeleteCommand = builder1.GetDeleteCommand();
                adapter1.UpdateCommand = builder1.GetUpdateCommand();
                adapter1.Update(objTable);
                builder1.Dispose();
                command1.Dispose();
                adapter1.Dispose();
            }
            else
            {
                adapter1 = new OleDbDataAdapter(this.m_objCommand);
                builder1 = new OleDbCommandBuilder(adapter1);
                adapter1.InsertCommand = builder1.GetInsertCommand();
                adapter1.DeleteCommand = builder1.GetDeleteCommand();
                adapter1.UpdateCommand = builder1.GetUpdateCommand();
                adapter1.Update(objTable);
                builder1.Dispose();
                adapter1.Dispose();
            }
        }
Exemple #22
0
 public void UpdateUserServer(UserDetail User, DataSet DS)    //פעולה מקבלת טבלה ופרטי משתמש
 {
     foreach (DataRow Row in DS.Tables["Users"].Rows)
     {
         if (User.UserId == int.Parse(Row["UserId"].ToString()))
         {
             Row["State"]        = User.State;
             Row["FirstName"]    = User.FirstName;
             Row["Email"]        = User.Email;
             Row["KindUser"]     = User.KindUser;
             Row["Description"]  = User.Description;
             Row["Status"]       = User.Status;
             Row["LastName"]     = User.LastName;
             Row["CardID"]       = User.CardID;
             Row["dateCard"]     = User.dateCard;
             Row["SecurityCode"] = User.SecurityCode;
             Row["DateAdd"]      = User.DateAdd;
             Row["birthday"]     = User.birthday;
         }
     }
     try
     {
         MyConnction.Open();
         OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
         adapter.UpdateCommand = builder.GetUpdateCommand();
         adapter.Update(DS, "Users");
     }
     catch (Exception err)
     { throw err; }
     finally { MyConnction.Close(); }
 }
Exemple #23
0
 public void insertInfo(string input)//插入信息
 {
     dataAdapter.InsertCommand = command.GetInsertCommand();
     dataAdapter.UpdateCommand = command.GetUpdateCommand();
     string[] inputs = Regex.Split(input, " ");
     if (inputs.Length != 8)
     {
         Console.WriteLine("错误的输入格式");
     }
     else
     {
         DataRow dr = dataTable.NewRow();
         dr["学号"]  = int.Parse(inputs[0]);
         dr["姓名"]  = inputs[1];
         dr["性别"]  = inputs[2];
         dr["班级"]  = int.Parse(inputs[3]);
         dr["邮箱"]  = inputs[4];
         dr["成绩1"] = int.Parse(inputs[5]);
         dr["成绩2"] = int.Parse(inputs[6]);
         dr["成绩3"] = int.Parse(inputs[7]);
         dataTable.Rows.Add(dr);
         dataAdapter.Update(dataTable);
         Console.WriteLine("输入成功");
     }
 }
Exemple #24
0
    /// <summary>
    /// 通过 OleDbDataAdapter 更新 DataSet 中变化的数据
    /// </summary>
    /// <param name="sqlstr">OleDbDataAdapter</param>
    /// <param name="sqlstr">OleDbCommandBuilder</param>
    /// <param name="sqlstr">DataSet</param>
    /// <returns>布尔值</returns>
    public static bool ExecuteUpdate(OleDbDataAdapter myAdapter, OleDbCommandBuilder myCommandBuilder, DataSet ds)
    {
        int i_return;

        try
        {
            myAdapter.UpdateCommand = myCommandBuilder.GetUpdateCommand();
            i_return = myAdapter.Update(ds);
            ds.Dispose();
            myAdapter.Dispose();
        }
        catch (Exception e)
        {
            throw new Exception(e.Message);
        }
        finally
        {
            closeConnection();
        }
        if (i_return > 0)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Exemple #25
0
        /*public static iDB2DataAdapter getiDB2DataAdapter(String DBType, String Sql, String sqlType)
         * {
         *  iDB2DataAdapter da;
         *  iDB2Connection dbConn = new iDB2Connection();
         *  dbConn.ConnectionString = getConnStr(DBType);
         *  //dbConn.ConnectionString = "Provider=IBMDA400;Database=R21AFLBZ;Hostname=172.31.71.37;Uid=ITSDTS;Pwd=STD008;";
         *  if (dbConn.State != System.Data.ConnectionState.Open)
         *      dbConn.Open();
         *  da = new iDB2DataAdapter(Sql, dbConn);
         *  if (sqlType.ToUpper() == "PROCEDURE")
         *  {
         *      da.SelectCommand.CommandType = CommandType.StoredProcedure;
         *  }
         *  else
         *  {
         *      iDB2CommandBuilder builder = new iDB2CommandBuilder(da);
         *      try
         *      {
         *          da.DeleteCommand = builder.GetDeleteCommand();
         *          da.UpdateCommand = builder.GetUpdateCommand();
         *          da.InsertCommand = builder.GetInsertCommand();
         *      }
         *      catch (Exception e)
         *      {
         *          Console.WriteLine(e.ToString());
         *      }
         *  }
         *  return da;
         * }
         */
        public static OleDbDataAdapter getOleDbDataAdapter(DbConnection Conn, String Sql, String SqlType)
        {
            OleDbDataAdapter da;
            OleDbConnection  dbConn = (OleDbConnection)Conn;

            //dbConn.ConnectionString = "Provider=IBMDA400;Database=R21AFLBZ;Hostname=172.31.71.37;Uid=ITSDTS;Pwd=STD008;";
            if (dbConn.State != ConnectionState.Open)
            {
                dbConn.Open();
            }
            da = new OleDbDataAdapter(Sql, dbConn);
            if (SqlType.ToUpper() == "PROCEDURE")
            {
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
            }
            else
            {
                try
                {
                    OleDbCommandBuilder builder = new OleDbCommandBuilder(da);
                    da.DeleteCommand = builder.GetDeleteCommand();
                    da.UpdateCommand = builder.GetUpdateCommand();
                    da.InsertCommand = builder.GetInsertCommand();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }

            return(da);
        }
Exemple #26
0
        private void button_showTable_Click(object sender, EventArgs e)
        {
            BindingSource bs1 = new BindingSource();

            // создаем экземпляр класса OleDbConnection
            myConnection = new OleDbConnection(connectString.ConnectionString);
            // открываем соединение с БД
            myConnection.Open();
            var    changeTable = comboBox1.SelectedItem.ToString();
            string sqlCommand  = String.Format("SELECT * FROM {0}", changeTable);

            da = new OleDbDataAdapter(sqlCommand, myConnection);
            dt = new DataTable();

            //фиксирование изменений
            OleDbCommandBuilder bulder = new OleDbCommandBuilder(da);

            da.UpdateCommand = bulder.GetUpdateCommand();
            da.InsertCommand = bulder.GetInsertCommand();
            da.DeleteCommand = bulder.GetDeleteCommand();

            da.Fill(dt);
            bs1.DataSource = dt;
            //dataGridView1.DataSource = dt; //выводим в грид
            bindingNavigator1.BindingSource = bs1;
            dataGridView1.DataSource        = bs1;

            myConnection.Close();
        }
Exemple #27
0
        private void button4_Click(object sender, EventArgs e)
        {
            OleDbCommandBuilder cb = new OleDbCommandBuilder(da);

            bs.EndEdit();
            da.UpdateCommand = cb.GetUpdateCommand();
            da.Update(ds, "mor");
        }
        //--------------------------------------------------------
        /// <summary>Creates a OleDbCommand object for the update stored procedure</summary>
        /// <returns>Initalized OleDbCommand object</returns>
        public virtual OleDbCommand GetUpdateCmd()
        {
            _da.SelectCommand = GetSelectCmd(0);             //GetListCmd();
            OleDbCommandBuilder builder = new OleDbCommandBuilder(_da);

            builder.QuotePrefix = "[";
            builder.QuoteSuffix = "]";
            return(builder.GetUpdateCommand());
        }
Exemple #29
0
        private void buttonDBSync_Click(object sender, EventArgs e)
        {
            OleDbCommandBuilder builder = new OleDbCommandBuilder(adapterArtikel);

            adapterArtikel.DeleteCommand = builder.GetDeleteCommand();
            adapterArtikel.InsertCommand = builder.GetInsertCommand();
            adapterArtikel.UpdateCommand = builder.GetUpdateCommand();
            adapterArtikel.Update(ds.Tables["Artikel"]);
        }
Exemple #30
0
        void button1_Click(object sender, EventArgs e)
        {
            var cb = new OleDbCommandBuilder(adapter);

            //cb.QuotePrefix = "[";           cb.QuoteSuffix = "]";
            adapter.UpdateCommand = cb.GetUpdateCommand();
            adapter.InsertCommand = cb.GetInsertCommand();
            adapter.Update(ds);
        }