예제 #1
0
        public int SaveDataTable(System.Data.DataTable dt)
        {
            SQLiteTransaction tran = null;

            try
            {
                SQLiteDataAdapter    adapter    = new SQLiteDataAdapter();
                string               sql        = string.Format(@"select * from {0} where 1=2", dt.TableName);
                SQLiteCommand        cmd        = new SQLiteCommand(_Conn);;
                SQLiteCommandBuilder comBuilder = new SQLiteCommandBuilder();

                comBuilder.DataAdapter = adapter;
                cmd.CommandText        = sql;
                cmd.Connection         = _Conn;
                adapter.SelectCommand  = cmd;
                adapter.InsertCommand  = comBuilder.GetInsertCommand();
                adapter.UpdateCommand  = comBuilder.GetUpdateCommand();
                adapter.DeleteCommand  = comBuilder.GetDeleteCommand();

                tran            = _Conn.BeginTransaction();//transaction begin 传说中sqlite每执行一条insert语句都开启一个事务,死慢
                cmd.Transaction = tran;
                int result = adapter.Update(dt);
                tran.Commit();//transaction end
                return(result);
            }
            catch (Exception ex)
            {
                if (tran != null)
                {
                    tran.Rollback();
                }

                throw ex;
            }
        }
예제 #2
0
        /// <summary>
        /// Load data from database to datagrid
        /// </summary>
        private void LoadData()
        {
            try
            {
                sqlDataAdapter = new SQLiteDataAdapter("Select *, 'Delete' AS [Delete] FROM " + currentTable, SqlConnection);

                SqlCommandBuilder = new SQLiteCommandBuilder(sqlDataAdapter);

                SqlCommandBuilder.GetInsertCommand();
                SqlCommandBuilder.GetUpdateCommand();
                SqlCommandBuilder.GetDeleteCommand();

                dataSet = new DataSet();

                sqlDataAdapter.Fill(dataSet, currentTable);

                dataGridView1.DataSource = null;
                dataGridView1.DataSource = dataSet.Tables[currentTable];

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    DataGridViewLinkCell linkCell = new DataGridViewLinkCell();
                    dataGridView1[lastIndexTable, i] = linkCell;
                }

                dataGridView1.Refresh();
                dataGridView1.Update();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void UpdateSellerInfo(int Index)
        {
            using (SQLiteConnection connection = new SQLiteConnection(Tools.DataTools.getConnectionString))
            {
                using (SQLiteCommand sqliteCommand = new SQLiteCommand("Select * From OrderedItems", connection))
                {
                    using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(sqliteCommand))
                    {
                        connection.Open();
                        DataRow dRow;
                        DataSet dSet = new DataSet();
                        adapter.Fill(dSet);
                        dRow = dSet.Tables[0].Rows[Form1.SelectedIndex];

                        dRow[25] = txtbxsellerName.Text;
                        dRow[26] = txtbxsellerTrackService.Text;
                        dRow[27] = txtbxExtraInfo.Text;

                        SQLiteCommandBuilder commBuild;
                        commBuild             = new SQLiteCommandBuilder(adapter);
                        adapter.UpdateCommand = commBuild.GetUpdateCommand(true);
                        adapter.Update(dSet);
                    }
                }
            }
        }
예제 #4
0
        public Query GetTableContent(Sql8rServer server, Sql8rDatabase database, Sql8rTable table, bool editable)
        {
            string sql   = "SELECT * FROM {0};";
            string dbSQL = string.Format(sql, table.Name);

            string dbConn = ConnectionString;

            using (var conn = new SQLiteConnection(dbConn))
            {
                conn.Open();

                var cmd = new SQLiteCommand(dbSQL, conn);

                var sdaDatabases = new SQLiteDataAdapter(cmd);

                if (editable)
                {
                    var scb = new SQLiteCommandBuilder(sdaDatabases);
                    sdaDatabases.UpdateCommand = scb.GetUpdateCommand();
                    sdaDatabases.InsertCommand = scb.GetInsertCommand();
                    sdaDatabases.DeleteCommand = scb.GetDeleteCommand();
                }


                var dsDatabases = new DataTable("TableContent");
                sdaDatabases.Fill(dsDatabases);

                var query = new Query(_settings, server.Name, database.Name, dbSQL, dsDatabases);
                query.Adapter = sdaDatabases;
                return(query);
            }
        }
예제 #5
0
        public int Update <T>(DataTable dt)
        {
            int count             = 0;
            SQLiteConnection conn = new SQLiteConnection(ConnectionStr);
            SQLiteCommand    comm = new SQLiteCommand(" select * from " + typeof(T).Name + " limit 1 ", conn);

            try
            {
                conn.Open();
                SQLiteTransaction    ts      = conn.BeginTransaction();
                SQLiteDataAdapter    dadpter = new SQLiteDataAdapter(comm);
                SQLiteCommandBuilder buider  = new SQLiteCommandBuilder(dadpter);
                dadpter.InsertCommand = buider.GetUpdateCommand();
                count = dadpter.Update(dt);
                ts.Commit();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(count);
        }
        public static void UpdateImage(int Index)
        {
            OrdersInfo = new DataSet();
            try
            {
                using (connection = new SQLiteConnection(ConnectionString))
                {
                    using (SQLiteCommand sqliteCommand = new SQLiteCommand(QueryOrdersShow, connection))
                    {
                        connection.Open();

                        using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(sqliteCommand))
                        {
                            DataRow dRow;
                            adapter.Fill(OrdersInfo);
                            dRow    = OrdersInfo.Tables[0].Rows[Index];
                            dRow[3] = convertImage(imagePath);
                            MessageBox.Show("Image Attached");

                            SQLiteCommandBuilder commBuild;
                            commBuild             = new SQLiteCommandBuilder(adapter);
                            adapter.UpdateCommand = commBuild.GetUpdateCommand(true);
                            adapter.Update(OrdersInfo);
                        }
                    }
                }
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
            }
        }
예제 #7
0
        private void LoadData()
        {
            SQLiteCommand command = _con.CreateCommand();

            command.CommandText = "SELECT MAX(bizonylatszam) FROM befizetesek";
            bizonylatszam       = Convert.ToInt32(command.ExecuteScalar());

            _adapTagok       = new SQLiteDataAdapter("SELECT * FROM tagok", _con);
            _adapBefizetesek = new SQLiteDataAdapter("SELECT * FROM befizetesek", _con);

            SQLiteCommandBuilder _builderTagok = new SQLiteCommandBuilder(_adapTagok);

            _adapTagok.InsertCommand = _builderTagok.GetInsertCommand();
            _adapTagok.DeleteCommand = _builderTagok.GetDeleteCommand();
            _adapTagok.UpdateCommand = _builderTagok.GetUpdateCommand();

            SQLiteCommandBuilder _builderBefizetesek = new SQLiteCommandBuilder(_adapBefizetesek);

            _adapBefizetesek.InsertCommand = _builderBefizetesek.GetInsertCommand();
            _adapBefizetesek.DeleteCommand = _builderBefizetesek.GetDeleteCommand();
            _adapBefizetesek.UpdateCommand = _builderBefizetesek.GetUpdateCommand();

            _dataSet = new DataSet("befizetesek");

            _adapTagok.Fill(_dataSet, "tagok");
            _bindingSourceTagok.DataSource = _dataSet.Tables["tagok"];
            _dataGridViewTagok.DataSource  = _bindingSourceTagok;

            _adapBefizetesek.Fill(_dataSet, "befizetesek");
            _bindingSourceBefizetesek.DataSource = _dataSet.Tables["befizetesek"];
            _dataGridViewBefizetesek.DataSource  = _bindingSourceBefizetesek;

            FormatTagokTable();
            FormatBefizetesekTable();
        }
        private void UpdateCCInfo()
        {
            using (SQLiteConnection connection = new SQLiteConnection(Tools.DataTools.getConnectionString))
            {
                using (SQLiteCommand sqliteCommand = new SQLiteCommand("Select * From OrderedItems", connection))
                {
                    using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(sqliteCommand))
                    {
                        connection.Open();
                        DataRow dRow;
                        DataSet dSet = new DataSet();
                        adapter.Fill(dSet);
                        dRow = dSet.Tables[0].Rows[Form1.SelectedIndex];

                        dRow[16] = txtbxCCFee.Text;
                        dRow[17] = txtbxCCDate.Text;

                        SQLiteCommandBuilder commBuild;
                        commBuild             = new SQLiteCommandBuilder(adapter);
                        adapter.UpdateCommand = commBuild.GetUpdateCommand(true);
                        adapter.Update(dSet);
                    }
                }
            }
        }
        public SQLiteDataAdapter GetDataAdapterSql(string sqlSelect, string sqlUpdate)
        {
            SQLiteCommand select       = new SQLiteCommand(sqlSelect, cnSQL);
            SQLiteCommand selectUpdate = new SQLiteCommand(sqlUpdate, cnSQL);
            //выявляем параметры в запросе и создаем их в команде
            int p = 0;

            while (p < sqlSelect.Length)
            {
                p = sqlSelect.IndexOf('@', p);
                if (p < 0)
                {
                    break;
                }
                int p2;
                for (p2 = ++p; p2 < sqlSelect.Length; p2++)                 //ищем конец имени поля
                {
                    if (!char.IsLetterOrDigit(sqlSelect[p2]))
                    {
                        break;
                    }
                }
                select.Parameters.Add(new SQLiteParameter(sqlSelect.Substring(p, p2 - p), null));
            }
            SQLiteDataAdapter    da = new SQLiteDataAdapter(selectUpdate);
            SQLiteCommandBuilder cb = new SQLiteCommandBuilder(da);

            cb.QuotePrefix   = "[";
            cb.QuoteSuffix   = "]";
            da.UpdateCommand = cb.GetUpdateCommand();
            da.InsertCommand = cb.GetInsertCommand();
            da.DeleteCommand = cb.GetDeleteCommand();
            da.SelectCommand = select;
            return(da);
        }
예제 #10
0
        private void button1_Click(object sender, EventArgs e) //修改产品
        {
            MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
            DialogResult      dr         = MessageBox.Show("确定要修改该产品数据吗", "提示!", messButton);

            if (dr == DialogResult.OK)
            {
                try
                {
                    SQLiteCommandBuilder scb = new SQLiteCommandBuilder(da);
                    da.UpdateCommand = scb.GetUpdateCommand();
                    da.Update(ds, "ProductInfo");
                }
                catch
                {
                    MessageBox.Show("修改错误!");
                    return;
                }
                MessageBox.Show("修改成功!");
            }
            else
            {
                return;
            }
        }
예제 #11
0
        internal void event_CommitDataTableChanges(string tableName, DataTable dataTable)
        {
            try {
                event_OpenConnection();
                string query = "SELECT * FROM [" + tableName + "]";

                SQLiteDataAdapter dataAdapter;
                dataAdapter = new SQLiteDataAdapter(query, connection);

                SQLiteCommandBuilder commandBuilder;
                commandBuilder             = new SQLiteCommandBuilder(dataAdapter);
                commandBuilder.QuotePrefix = "[";
                commandBuilder.QuoteSuffix = "]";

                dataAdapter.DeleteCommand = commandBuilder.GetDeleteCommand();
                dataAdapter.UpdateCommand = commandBuilder.GetUpdateCommand();
                dataAdapter.InsertCommand = commandBuilder.GetInsertCommand();
                dataAdapter.Update(dataTable);
                commandBuilder.Dispose();
                dataAdapter.Dispose();
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
예제 #12
0
 public bool SaveDataGrid()
 {
     try
     {
         if (connection == null)
         {
             return(true);
         }
         dataGridView.CurrentCell = null;
         comandBuilder.RefreshSchema();
         dataGridView.EndEdit();
         if (adapter.InsertCommand == null)
         {
             adapter.InsertCommand = new SQLiteCommand(" ");
         }
         if (adapter.UpdateCommand == null)
         {
             adapter.UpdateCommand = comandBuilder.GetUpdateCommand();
         }
         if (adapter.DeleteCommand == null)
         {
             adapter.DeleteCommand = comandBuilder.GetDeleteCommand();
         }
         adapter.Update(dataSet.Tables[NameTable]);
         return(true);
     }
     catch (Exception e)
     {
         MessageBox.Show("Ошибка в процессе сохранения данных.\n" + e.Message, "Ошибка");
         return(false);
     }
 }
예제 #13
0
        private void applyButton_Click(object sender, EventArgs e)
        {
            SQLiteConnection     mCN = ConnectionManager.connection;
            SQLiteDataAdapter    mDA = modulesTableAdapter.Adapter;
            SQLiteCommandBuilder mCB = new SQLiteCommandBuilder(mDA);
            DataSet mDS       = modulesDataSet;
            DataSet dsChanges = new DataSet();

            if (!mDS.HasChanges())
            {
                return;
            }
            dsChanges = mDS.GetChanges(DataRowState.Modified);
            if (dsChanges != null)
            {
                mDA.UpdateCommand = mCB.GetUpdateCommand();
                mDA.Update(dsChanges, "modules");
            }
            dsChanges = mDS.GetChanges(DataRowState.Added);
            if (dsChanges != null)
            {
                mDA.InsertCommand = mCB.GetInsertCommand();
                mDA.Update(dsChanges, "modules");
            }
            dsChanges = mDS.GetChanges(DataRowState.Deleted);
            if (dsChanges != null)
            {
                mDA.DeleteCommand = mCB.GetDeleteCommand();
                mDA.Update(dsChanges, "modules");
            }
            mDS.AcceptChanges();
            UpdateModulesDropDown();
            (treeView.Model as SlowTreeModel).Root.UpdateModulesFromDbRec();
            treeView.Invalidate();
        }
예제 #14
0
        public int?UpdateDt(DataTable Dt, string commandText)
        {
            //if application is exiting the don't perform DB process
            if (this.isAppClosing)
            {
                return(null);
            }

            if (!DoesDBConnectionExists())
            {
                return(null);
            }

            try
            {
                SQLiteDataAdapter    da = new SQLiteDataAdapter(commandText, _connection);
                SQLiteCommandBuilder cb = new SQLiteCommandBuilder(da);
                da.UpdateCommand = cb.GetUpdateCommand();
                da.InsertCommand = cb.GetInsertCommand();
                da.DeleteCommand = cb.GetDeleteCommand();
                da.Update(Dt);
            }
            catch (Exception ex)
            {
                LogTrace.WriteErrorLog(this.GetType().Name, MethodBase.GetCurrentMethod().Name,
                                       String.Format("Error in query . " + commandText + ex.StackTrace));
                throw;
            }
            finally
            {
                commandText = string.Empty;
            }

            return(Dt.Rows.Count);
        }
예제 #15
0
    public Form1()
    {
        InitializeComponent();
        var c  = Connect();
        var da = new SQLiteDataAdapter("select emp_id, emp_firstname, emp_lastname from emp where 1 = 0", c);

        var b = new SQLiteCommandBuilder(da);

        da.InsertCommand = new SQLiteCommand(
            @"insert into emp(emp_firstname, emp_lastname ) values(:_emp_firstname, :_emp_lastname);
                select emp_id, emp_firstname, emp_lastname from emp where emp_id = last_insert_rowid();", c);
        da.InsertCommand.Parameters.Add("_emp_firstname", DbType.String, 0, "emp_firstname");
        da.InsertCommand.Parameters.Add("_emp_lastname", DbType.String, 0, "emp_lastname");
        da.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;
        da.UpdateCommand = b.GetUpdateCommand();
        da.DeleteCommand = b.GetDeleteCommand();
        var dt = new DataTable();

        da.Fill(dt);
        var nr = dt.NewRow();

        nr["emp_firstname"] = "john";
        nr["emp_lastname"]  = "lennon";
        dt.Rows.Add(nr);
        da.Update(dt);
        dt.AcceptChanges();
        nr["emp_lastname"] = "valjean";
        da.Update(dt);
    }
예제 #16
0
        /// <summary>
        /// DataAdapterのUpdateComandを自動生成
        /// </summary>
        /// <remarks></remarks>
        public void BuildUpdateCommand()
        {
            //UpdateCommandを作成
            SQLiteCommandBuilder sqlCmdBuilder = new SQLiteCommandBuilder(_da);

            sqlCmdBuilder.GetUpdateCommand();
        }
        private static void clearImage(int Index)
        {
            OrdersInfo = new DataSet();
            try
            {
                using (connection = new SQLiteConnection(ConnectionString))
                {
                    using (SQLiteCommand sqliteCommand = new SQLiteCommand(QueryOrdersShow, connection))
                    {
                        connection.Open();

                        using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(sqliteCommand))
                        {
                            DataRow dRow;
                            adapter.Fill(OrdersInfo);
                            dRow                = OrdersInfo.Tables[0].Rows[Index];
                            dRow[3]             = null;
                            pcbxPackImage.Image = Properties.Resources.NoImageAvailable;

                            SQLiteCommandBuilder commBuild;
                            commBuild             = new SQLiteCommandBuilder(adapter);
                            adapter.UpdateCommand = commBuild.GetUpdateCommand(true);
                            adapter.Update(OrdersInfo);
                        }
                    }
                }
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
            }
        }
        } // ახალი ამანათის დამატების ფუნქცია

        public static void deleteRecord(int Index)
        {
            OrdersInfo = new DataSet();
            try
            {
                using (connection = new SQLiteConnection(ConnectionString))
                {
                    using (SQLiteCommand sqliteCommand = new SQLiteCommand(QueryOrdersShow, connection))
                    {
                        connection.Open();

                        using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(sqliteCommand))
                        {
                            adapter.Fill(OrdersInfo);
                            OrdersInfo.Tables[0].Rows[Index].Delete();

                            SQLiteCommandBuilder commBuild;
                            commBuild             = new SQLiteCommandBuilder(adapter);
                            adapter.UpdateCommand = commBuild.GetUpdateCommand(true);
                            adapter.Update(OrdersInfo);
                            MessageBox.Show("Package Removed...");
                        }
                    }
                }
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
            }
        } // წაშლა
        private void button2_Click(object sender, EventArgs e)
        {
            // ekle liste güncelleme
            SQLiteCommandBuilder builder = new SQLiteCommandBuilder(adp);

            builder.GetUpdateCommand();
            sorulariSil();
            adp.Update(dt);

            baglanti.Open();
            cmd = new SQLiteCommand("UPDATE GvnGenel SET dersGuncelleme=1, eklemeVarmi=1", baglanti);
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            baglanti.Close();

            if (dersSilmeDegisiklik == true)
            {
                //Haftaya programla devre dışı bırakma !
                baglanti.Open();
                cmd = new SQLiteCommand("UPDATE GvnGenel SET HaftayaProgramlamaPA='Pasif', HPOrtaOkul='Pasif', HPLise='Pasif' WHERE id=1", baglanti);
                cmd.ExecuteNonQuery();
                cmd.Dispose();
                baglanti.Close();
                dersSilmeDegisiklik = false;

                MessageBox.Show("Güncellendi. Otomatik programla pasif durumuna getirildi. Lütfen aktifleştiriniz.", "Ders Ekle", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            }
            else
            {
                MessageBox.Show("Güncellendi.", "Ders Ekle", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            }
        }
예제 #20
0
 public void sync()
 {
     using (SQLiteCommandBuilder builder = new SQLiteCommandBuilder(m_dataAdapter))
     {
         //m_dataAdapter.DeleteCommand = builder.GetDeleteCommand(true);
         m_dataAdapter.UpdateCommand = builder.GetUpdateCommand(true);
         m_dataAdapter.Update(ds);
     }
 }
예제 #21
0
        public void write()
        {
            SQLiteCommandBuilder cb = new SQLiteCommandBuilder(_aSQLiteDataAdapter);

            cb.QuotePrefix = "[";
            cb.QuoteSuffix = "]";
            _aSQLiteDataAdapter.InsertCommand = cb.GetUpdateCommand();
            _aSQLiteDataAdapter.Update(dataSet);
        }
예제 #22
0
        static void Update(string tableName)
        {
            var adapter        = Adapters[tableName];
            var commandBuilder = new SQLiteCommandBuilder(adapter);

            adapter.DeleteCommand = commandBuilder.GetDeleteCommand(true);
            adapter.InsertCommand = commandBuilder.GetInsertCommand(true);
            adapter.UpdateCommand = commandBuilder.GetUpdateCommand(true);
            adapter.Update(Tables[tableName]);
        }
예제 #23
0
        public void Push()
        {
            var builder = new SQLiteCommandBuilder(_adapter);

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

            _adapter.Update(LocalDataTable);
        }
예제 #24
0
        public override DbDataAdapter CreateAdapter(Table table, TableFilter filter)
        {
            if (!(table is SQLiteTable))
            {
                throw new ArgumentException("Table must be of type SQLiteTable", "table");
            }
            var adapter = new SQLiteDataAdapter(table.GetBaseSelectCommandText(filter), Connection);

            if (!table.IsReadOnly)
            {
                var builder = new SQLiteCommandBuilder(adapter)
                {
                    ConflictOption = ConflictOption.OverwriteChanges
                };

                SQLiteCommand updateCommand = null;
                try {
                    updateCommand = builder.GetUpdateCommand();
                } catch (InvalidOperationException) {
                    var selectSql = new StringBuilder();
                    selectSql.Append("SELECT RowId, ");
                    filter.WriteColumnsProjection(selectSql);
                    selectSql.Append(" FROM ");
                    selectSql.Append(table.QuotedName);

                    adapter       = new SQLiteDataAdapter(selectSql.ToString(), Connection);
                    builder       = new SQLiteCommandBuilder(adapter);
                    updateCommand = builder.GetUpdateCommand();
                }
                var insertCommand = builder.GetInsertCommand();

                foreach (var column in table.Columns)
                {
                    if (column.IsIdentity)
                    {
                        insertCommand.CommandText      = insertCommand.CommandText + "; SELECT @RowId = last_insert_rowid()";
                        insertCommand.UpdatedRowSource = UpdateRowSource.OutputParameters;
                        var parameter = new SQLiteParameter {
                            ParameterName = "@RowId",
                            Direction     = ParameterDirection.Output,
                            SourceColumn  = column.Name,
                            SourceVersion = DataRowVersion.Current,
                            Value         = DBNull.Value
                        };
                        insertCommand.Parameters.Add(parameter);
                        break;
                    }
                }
                adapter.UpdateCommand = updateCommand;
                adapter.InsertCommand = insertCommand;
                adapter.DeleteCommand = builder.GetDeleteCommand();
            }
            return(adapter);
        }
예제 #25
0
        private void UpdateDatabase()
        {
            using (var connection = GetConnection())
            {
                var query   = "select * from features";
                var adapter = new SQLiteDataAdapter(query, connection);
                var builder = new SQLiteCommandBuilder(adapter);

                adapter.UpdateCommand = builder.GetUpdateCommand();
                adapter.Update(DataTable);
            }
        }
        public SQLiteDataAdapter GetSQLiteAdapter(string SelectCommand)
        {
            SQLiteDataAdapter adapter = new SQLiteDataAdapter(SelectCommand, this.connection);

            SQLiteCommandBuilder cb = new SQLiteCommandBuilder(adapter);

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

            return(adapter);
        }
예제 #27
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            _ad = new SQLiteDataAdapter("select * from students", DB.Connection);
            var builder = new SQLiteCommandBuilder(_ad);

            _ad.DeleteCommand = builder.GetDeleteCommand();
            _ad.InsertCommand = builder.GetInsertCommand();
            _ad.UpdateCommand = builder.GetUpdateCommand();
            _ad.Fill(_dt);
            btnEdit.Enabled        = btnRemove.Enabled = _dt.Rows.Count != 0;
            listBox1.DataSource    = _dt;
            listBox1.DisplayMember = "name";
        }
예제 #28
0
 private void CveDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         SQLiteCommandBuilder scb = new SQLiteCommandBuilder(mAdapter);
         mAdapter.UpdateCommand = scb.GetUpdateCommand();
         mAdapter.Update(ds, t_name);
         //SelectAll();
         //CveDataGridView.Rows[CveDataGridView.Rows.Count - 1].Selected = true;
     }
     catch (Exception)
     {
     }
 }
예제 #29
0
        public void Update(DataTable dataTable)
        {
            var query = $"select * from {TableName}";

            using (SQLiteConnection connection = GetConnection())
                using (var adapter = new SQLiteDataAdapter(query, connection))
                    using (var commandBuilder = new SQLiteCommandBuilder(adapter))
                    {
                        adapter.UpdateCommand = commandBuilder.GetUpdateCommand();
                        adapter.DeleteCommand = commandBuilder.GetDeleteCommand();
                        adapter.InsertCommand = commandBuilder.GetInsertCommand();
                        adapter.Update(dataTable);
                    }
        }
예제 #30
0
        private void LoadData()
        {
            SQLiteCommand command = _con.CreateCommand();

            command.CommandText = "SELECT MAX(kolcson_id) FROM kolcsonzesek";
            kolcson_id          = Convert.ToInt32(command.ExecuteScalar());

            _adapKolcsonzesek = new SQLiteDataAdapter("SELECT * FROM kolcsonzesek WHERE vissza is null", _con);
            _adapTagok        = new SQLiteDataAdapter("SELECT * FROM tagok", _con);
            _adapKonyvek      = new SQLiteDataAdapter("SELECT * FROM konyvek", _con);

            SQLiteCommandBuilder _builderKolcsonzesek = new SQLiteCommandBuilder(_adapKolcsonzesek);

            _adapKolcsonzesek.InsertCommand = _builderKolcsonzesek.GetInsertCommand();
            _adapKolcsonzesek.DeleteCommand = _builderKolcsonzesek.GetDeleteCommand();
            _adapKolcsonzesek.UpdateCommand = _builderKolcsonzesek.GetUpdateCommand();

            SQLiteCommandBuilder _builderTagok = new SQLiteCommandBuilder(_adapTagok);

            _adapTagok.InsertCommand = _builderTagok.GetInsertCommand();
            _adapTagok.DeleteCommand = _builderTagok.GetDeleteCommand();
            _adapTagok.UpdateCommand = _builderTagok.GetUpdateCommand();

            SQLiteCommandBuilder _builderKonyvek = new SQLiteCommandBuilder(_adapKonyvek);

            _adapKonyvek.InsertCommand = _builderKonyvek.GetInsertCommand();
            _adapKonyvek.DeleteCommand = _builderKonyvek.GetDeleteCommand();
            _adapKonyvek.UpdateCommand = _builderKonyvek.GetUpdateCommand();


            _dataSet = new DataSet("kolcsonzes");


            _adapKolcsonzesek.Fill(_dataSet, "kolcsonzesek");
            _bindingSourceKolcsonzesek.DataSource = _dataSet.Tables["kolcsonzesek"];
            _dataGridViewKolcsonzesek.DataSource  = _bindingSourceKolcsonzesek;

            _adapTagok.Fill(_dataSet, "tagok");
            _bindingSourceTagok.DataSource = _dataSet.Tables["tagok"];
            _dataGridViewTagok.DataSource  = _bindingSourceTagok;

            _adapKonyvek.Fill(_dataSet, "konyvek");
            _bindingSourceKonyvek.DataSource = _dataSet.Tables["konyvek"];
            _dataGridViewKonyvek.DataSource  = _bindingSourceKonyvek;


            FormatKolcsonzesekTable();
            FormatTagokTable();
            FormatKonyvekTable();
        }