Update() protected method

protected Update ( DataRow dataRows, DataTableMapping tableMapping ) : int
dataRows System.Data.DataRow
tableMapping System.Data.Common.DataTableMapping
return int
        /// <summary>
        /// Initializes a new instance of the <see cref="ManagerAddExistingItemGui"/> class.
        /// </summary>
        /// <param name="jobID1">The job i d1.</param>
        public ManagerAddExistingItemGui(string jobID1)
        {
            this.jobID = jobID1;
            InitializeComponent();
            this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            jobid_label.Content = jobID;

            try
            {
                MySqlConnection MySqlConn = new MySqlConnection(Login.Connectionstring);
                MySqlConn.Open();
                string Query1 = ("select itemid as `מקט פריט`,itemName as `שם פריט`, item_discription as `תאור פריט` from project.item WHERE itemStatus='בעבודה' group by itemid");
                MySqlCommand MSQLcrcommand1 = new MySqlCommand(Query1, MySqlConn);
                MSQLcrcommand1.ExecuteNonQuery();
                MySqlDataAdapter mysqlDAdp = new MySqlDataAdapter(MSQLcrcommand1);
                //DataTable dt1 = new DataTable("items");
                mysqlDAdp.Fill(dt);
                Create_DataTable1_Columns_End();
                //   Make_CheckBox1_Columns_False();
                dataGrid1.ItemsSource = dt.DefaultView;
                mysqlDAdp.Update(dt);

                MySqlConn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {

                progressBar1.Value = 15;
                var mydbconnection = new dbconnection();
                progressBar1.Value = 30;
                string query = "SELECT * FROM inventory";
                MySqlCommand cmd = new MySqlCommand(query, mydbconnection.getconnect);
                progressBar1.Value = 50;
                MySqlDataAdapter sda = new MySqlDataAdapter();
                sda.SelectCommand = cmd;
                DataTable dataset = new DataTable();
                sda.Fill(dataset);
                progressBar1.Value = 80;
                //BindingSource bsource = new BindingSource();
                //bsource.DataSource = dataset;
                inventorygrid.DataSource = dataset;
                sda.Update(dataset);
                progressBar1.Value = 100;
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
        }
Example #3
0
        private void ViewIssued_Load(object sender, EventArgs e)
        {
            try {
                string query;
                if (id == null) {
                    query = "select * from library.borrowed_books;";
                } else {
                    query = "select * from library.borrowed_books where card_no='" + id + "';";
                }
                MySqlConnection myConn = DB.GetDB();

                MySqlCommand cmdDataBase = new MySqlCommand (query, myConn);
                // MySqlDataReader myReader;

                MySqlDataAdapter sda = new MySqlDataAdapter ();
                sda.SelectCommand = cmdDataBase;
                DataTable dbDataset = new DataTable ();
                sda.Fill (dbDataset);
                BindingSource bsource = new BindingSource ();
                bsource.DataSource = dbDataset;
                dataGridView1.DataSource = bsource;
                sda.Update (dbDataset);

            } catch (Exception ex) {
                MessageBox.Show (ex.Message);
            }
        }
Example #4
0
        public void AutoIncrementColumns()
        {
            execSQL("DROP TABLE IF EXISTS Test");
            execSQL("CREATE TABLE Test (id int(10) unsigned NOT NULL auto_increment primary key)");
            execSQL("INSERT INTO Test VALUES(NULL)");

            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", conn);
            MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
            DataSet ds = new DataSet();
            da.Fill(ds);
            Assert.AreEqual(1, ds.Tables[0].Rows[0]["id"]);
            DataRow row = ds.Tables[0].NewRow();
            ds.Tables[0].Rows.Add(row);

            try
            {
                da.Update(ds);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }

            ds.Clear();
            da.Fill(ds);
            Assert.AreEqual(1, ds.Tables[0].Rows[0]["id"]);
            Assert.AreEqual(2, ds.Tables[0].Rows[1]["id"]);
            cb.Dispose();
        }
Example #5
0
        // public static DataGrid dataGrid1 = new DataGrid();
        /// <summary>
        /// Initializes a new instance of the <see cref="ManagerEMPGui"/> class.
        /// </summary>
        public ManagerEMPGui()
        {
            InitializeComponent();
            this.WindowStartupLocation = WindowStartupLocation.CenterScreen;

            try
            {
                MySqlConnection MySqlConn = new MySqlConnection(Login.Connectionstring);
                MySqlConn.Open();
                string Query1 = ("SELECT empid as `תעודת זהות`,emp_firstname as `שם פרטי` ,emp_lastname as `שם משפחה` , emp_insidenum as `מספר עובד` ,emp_address as `כתובת` ,emp_phone as `מספר טלפון`, emp_cellphone as `טלפון נייד`, emp_start_date as `תאריך התחלת עבודה` FROM project.employees ");
                MySqlCommand MSQLcrcommand1 = new MySqlCommand(Query1, MySqlConn);
                MSQLcrcommand1.ExecuteNonQuery();
                MySqlDataAdapter mysqlDAdp = new MySqlDataAdapter(MSQLcrcommand1);
                //DataTable dt = new DataTable("employess");
                dt.Clear();
                mysqlDAdp.Fill(dt);
                dataGrid1.ItemsSource = dt.DefaultView;
                mysqlDAdp.Update(dt);
                MySqlConn.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private void fillgridPerg()
 {
     id = -1;
     buttonDel.Visible = false;
     buttonEdit.Visible = false;
     buttonIns.Visible = false;
     buttonCancel.Visible = false;
     DBConnect NewcConnection = new DBConnect();
     NewcConnection.dbConnection();
     MySqlCommand querysql = new MySqlCommand("Select id_quest, id_qs, questao, name_qs From questionarios, questionset where id_qs_fk = id_qs", DBConnect.db);
     try
     {
         MySqlDataAdapter dados = new MySqlDataAdapter();
         dados.SelectCommand = querysql;
         DataTable tabela = new DataTable();
         dados.Fill(tabela);
         BindingSource fonte = new BindingSource();
         fonte.DataSource = tabela;
         dataGridView1.DataSource = fonte;
         this.dataGridView1.Columns[0].Visible = false;
         this.dataGridView1.Columns[1].Visible = false;
         dataGridView1.Columns[2].HeaderText = "Questão";
         dataGridView1.Columns[3].HeaderText = "QuestionSet";
         dados.Update(tabela);
         dataGridView1.AutoResizeColumns();
         dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     DBConnect.db.Close();
     textBoxPerg.Clear();
     comboBox1.SelectedIndex = 0;
 }
        private void fillgridDef()
        {
            id = -1;
            buttonDel.Visible = false;
            buttonEdit.Visible = false;
            buttonIns.Visible = false;
            buttonCancel.Visible = false;
            DBConnect NewcConnection = new DBConnect();
            NewcConnection.dbConnection();
            MySqlCommand querysql = new MySqlCommand("Select * From deficiencias", DBConnect.db);

            try
            {
                MySqlDataAdapter dados = new MySqlDataAdapter();
                dados.SelectCommand = querysql;
                DataTable tabela = new DataTable();
                dados.Fill(tabela);
                BindingSource fonte = new BindingSource();
                fonte.DataSource = tabela;
                dataGridView1.DataSource = fonte;
                this.dataGridView1.Columns[0].Visible = false;
                dataGridView1.Columns[1].HeaderText = "Deficiencia";
                dados.Update(tabela);
                dataGridView1.AutoResizeColumns();
                dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            DBConnect.db.Close();
            textBoxDef.Clear();
        }
Example #8
0
        public void UpdateData(string tableName, string tableColumn, int limit, Action<DataRow> action)
        {
            var dataSet = new DataSet();

            using (var connection = new MySqlConnection(GetConnectionString()))
            {
                connection.Open();
                var q = string.Format(Query, tableName, tableColumn, limit);
                var adapter = new MySqlDataAdapter
                    {
                        SelectCommand = new MySqlCommand(q, connection) { CommandTimeout = 300 },
                    };
                var builder = new MySqlCommandBuilder(adapter);

                adapter.Fill(dataSet);

                // Code to modify data in the DataSet here.
                foreach (DataRow row in dataSet.Tables[0].Rows)
                {
                    action(row);
                }

                adapter.UpdateCommand = builder.GetUpdateCommand();
                adapter.Update(dataSet);
            }
        }
Example #9
0
    public MainWindow()
        : base(Gtk.WindowType.Toplevel)
    {
        Build ();

        MySqlConnection mySqlConnection = new MySqlConnection (
            "DataSource=localhost;Database=dbprueba;User ID=root;Password=sistemas"
        );
        mySqlConnection.Open ();
        string selectSql = "select * from categoria"; //uso categoria ya que es el nombre que tengo en la BD
        MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter (selectSql, mySqlConnection);
        DataSet dataSet = new DataSet ();
        mySqlDataAdapter.Fill (dataSet);

        show (dataSet);

        DataTable dataTable = dataSet.Tables [0];
        DataRow dataRow = dataTable.Rows [0];
        dataRow ["nombre"] = DateTime.Now.ToString ();

        new MySqlCommandBuilder (mySqlDataAdapter);

        mySqlDataAdapter.Update (dataSet);

        mySqlDataAdapter.RowUpdating += delegate(object sender, MySqlRowUpdatingEventArgs e) {
            Console.WriteLine("e.Command.CommandText={0}", e.Command.CommandText);
        };
    }
Example #10
0
	public MainWindow (): base (Gtk.WindowType.Toplevel)
	{
		Build ();

		MySqlConnection mySqlConnection = new MySqlConnection(
			"DataSource=localhost;Database=dbprueba;User ID=root;Password=sistemas"
			);

		//DATA ADAPTER
		mySqlConnection.Open ();
		string selectSql = "select * from articulo";
		MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter (selectSql,mySqlConnection);

		//CREAR DATASET
		DataSet dataSet = new DataSet ();
		mySqlDataAdapter.Fill (dataSet);//LLENAMOS EL DATASET CON EL DATA ADAPTER

		show (dataSet);
		DataTable dataTable = dataSet.Tables [0];

		DataRow dataRow = dataTable.Rows [0];
		dataRow ["nombre"] = DateTime.Now.ToString ();

		new MySqlCommandBuilder (mySqlDataAdapter);//NECESARIO PARA EL UPDATE
		mySqlDataAdapter.Update (dataSet);//UPDATE A LA BASE DE DATOS

		mySqlDataAdapter.RowUpdating += delegate(object sender, MySqlRowUpdatingEventArgs e) {
			Console.WriteLine ("e.Command.CommandText={0}", e.Command.CommandText);
	};
	}
Example #11
0
        /// <summary>
        /// 插入数据通过Datatable
        /// </summary>
        /// <param name="_dt"></param>
        /// <returns>影响记录条数</returns>
        public override int DataTableInsert(DataTable _dt)
        {
            bool flag = false;
            int _nResult = 0;
            if (_dt == null)
                return _nResult;
            string _sCmdText = string.Format("select * from {0} where 1=2", _dt.TableName);
            MySqlCommand _Command = (MySqlCommand)CreateCommand(_sCmdText, CommandType.Text);
            MySqlDataAdapter _adapter = new MySqlDataAdapter(_Command);
            MySqlDataAdapter _adapter1 = new MySqlDataAdapter(_Command);
            MySqlCommandBuilder _builder = new MySqlCommandBuilder(_adapter1);

            _adapter.InsertCommand = _builder.GetInsertCommand();

            if (_adapter.InsertCommand.Parameters.Count < _dt.Columns.Count)
            {
                flag = true;//因为表中有自增字段,所以CommandBuild生成的InserttCommand的参数中少了自增字段
                foreach (DataColumn _dc in _dt.Columns)
                {
                    if (!_adapter.InsertCommand.Parameters.Contains(_dc.ColumnName))
                    {
                        _adapter.InsertCommand.CommandText =
                            _adapter.InsertCommand.CommandText.Insert(_adapter.InsertCommand.CommandText.IndexOf(") VALUES"), ',' + _dc.ColumnName);

                        _adapter.InsertCommand.CommandText =
                            _adapter.InsertCommand.CommandText.Insert(_adapter.InsertCommand.CommandText.Length - 1, ",@" + _dc.ColumnName);

                        _adapter.InsertCommand.Parameters.Add("@" + _dc.ColumnName, MySqlDbType.Decimal, _dc.MaxLength, _dc.ColumnName);

                        if (_adapter.InsertCommand.Parameters.Count >= _dt.Columns.Count)
                            break;
                    }
                }
            }

            if (flag)
                this.ExecuteNoQuery(string.Format("SET IDENTITY_INSERT {0} on", _dt.TableName));

            this.BeginTransaction();
            try
            {
                _adapter.InsertCommand.Transaction = _Command.Transaction;
                _Command.CommandText = "delete from " + _dt.TableName;
                _Command.ExecuteNonQuery();
                _nResult = _adapter.Update(_dt);
                this.CommitTransaction();
            }
            catch (Exception ex)
            {
                this.RollbackTransaction();
                throw ex;
            }
            finally
            {
                if (flag)
                    this.ExecuteNoQuery(string.Format("SET IDENTITY_INSERT {0} OFF", _dt.TableName));
            }
            return _nResult;
        }
Example #12
0
 public int SaveNewItems(ref DataTable NewItemTBL)
 {
     command = new MySqlCommand(SQL_SELECT_ITEM, GetDBConnection());
     adapter = new MySqlDataAdapter();
     adapter.SelectCommand = command;
     builder = new MySqlCommandBuilder(adapter);
     adapter.InsertCommand = builder.GetInsertCommand();
     adapter.ContinueUpdateOnError = true;
     return adapter.Update(NewItemTBL);
 }
 public void commitChanges(String query, DataTable dataTable)
 {
     lock (syncLock)
     {
         var adapter = new MySqlDataAdapter();
         var mcb = new MySqlCommandBuilder(adapter);
         adapter.SelectCommand = new MySqlCommand(query, conn);
         adapter.Update(dataTable);
         dataTable.AcceptChanges();
     }
 }
        public void AdapterConcurrentException()
        {
            execSQL(
            "CREATE TABLE T (" +
            "id_auto int(11) NOT NULL AUTO_INCREMENT," +
            "field varchar(50) DEFAULT NULL," +
            "PRIMARY KEY (id_auto))");

              MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM T", conn);
              da.InsertCommand = conn.CreateCommand();
              da.InsertCommand.CommandText = @"INSERT INTO T(field) VALUES (@p_field);
                                            SELECT * FROM T WHERE id_auto=@@IDENTITY";
              da.InsertCommand.Parameters.Add("@p_field", MySqlDbType.VarChar, 50, "field");
              da.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;

              da.DeleteCommand = conn.CreateCommand();
              da.DeleteCommand.CommandText = "DELETE FROM T WHERE id_auto=@id_auto";
              da.DeleteCommand.Parameters.Add("@id_auto", MySqlDbType.Int32, 4, "id_auto");

              DataSet ds = new DataSet();
              da.Fill(ds, "T");

              DataTable table = ds.Tables["T"];
              DataRow r = table.NewRow();
              r["field"] = "row";
              table.Rows.Add(r);
              da.Update(table);

              Assert.AreEqual(r.RowState, DataRowState.Unchanged);

              table.Rows[0].Delete();

              r = table.NewRow();
              r["field"] = "row2";
              table.Rows.Add(r);

              da.Update(table); // here was concurrencyviolation
              da.Fill(ds);
              Assert.AreEqual(ds.Tables["T"].Rows.Count, 1);
              Assert.AreEqual(ds.Tables["T"].Rows[0]["field"], "row2");
        }
Example #15
0
 public void FillGrid(string sql, ref DataGridView gridView)
 {
     var cmd = new MySqlCommand(sql, this.connection);
     cmd.CommandTimeout = 300;
     var adapter = new MySqlDataAdapter(cmd);
     var dataTable = new DataTable();
     adapter.Fill(dataTable);
     var bindingSource = new BindingSource();
     bindingSource.DataSource = dataTable;
     gridView.DataSource = bindingSource;
     adapter.Update(dataTable);
 }
Example #16
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (MenuSet.pwdSet == '0')
            {
                MessageBox.Show("没有设置该权限!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string strPwd = txtPwd.Text.Trim();
            string strSel = string.Format("SELECT * FROM rhdbs.user_info WHERE user_id='{0}' AND pwd='{1}'", TheToken.LoginUser, strPwd);

            DataTable dt = new DataTable();
            MySqlConnection conn = new MySqlConnection(TheToken.DataConnStr);
            conn.Open();
            MySqlDataAdapter da = new MySqlDataAdapter(strSel, conn);
            try
            {
                da.Fill(dt);
            }
            catch
            {
                MessageBox.Show("密码错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                if (txtPwdNew.Text != txtPwdNew2.Text)
                {
                    MessageBox.Show("两次输入密码不一致!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                dt.Rows[0].BeginEdit();
                dt.Rows[0]["pwd"] = txtPwdNew.Text;
                dt.Rows[0].EndEdit();
                MySqlCommandBuilder scb = new MySqlCommandBuilder(da);
                scb.ReturnGeneratedIdentifiers = false;
                da.Update(dt.GetChanges());
                dt.AcceptChanges();
            }
            catch
            {
                MessageBox.Show("密码错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            MessageBox.Show("密码修改成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        private void inventorylist_Load(object sender, EventArgs e)
        {            
            paisapayidprimarykeytbox.Text = salesentry.paisapayid2.ToString();
            var mydbconnection = new dbconnection();
            
            string query = "SELECT * FROM inventory";
            MySqlCommand cmd = new MySqlCommand(query, mydbconnection.getconnect);

            MySqlDataAdapter sda = new MySqlDataAdapter();
            sda.SelectCommand = cmd;
            DataTable dataset = new DataTable();
            sda.Fill(dataset);
            BindingSource bsource = new BindingSource();
            bsource.DataSource = dataset;
            dataGridView1.DataSource = dataset;
            sda.Update(dataset);
            /////////////////////////////////////////////////////////////////////////////
            DataColumn Item_SKU = new DataColumn("SKU", Type.GetType("System.String"));
            DataColumn Item_Name = new DataColumn("Item Name", Type.GetType("System.String"));
            DataColumn Item_Price = new DataColumn("Item_Price", Type.GetType("System.Decimal"));
            DataColumn Item_Qty = new DataColumn("Item_Qty", Type.GetType("System.Decimal"));
            DataColumn Item_totalwt = new DataColumn("With Out Tax", Type.GetType("System.Decimal"));
            DataColumn Item_Tax = new DataColumn("Item_tax", Type.GetType("System.Decimal"));
            // "Item_Tax" column is calculated (10% Tax)
            Item_Tax.Expression = "(Item_Price * Item_Qty)" + "/100" + "*" + Properties.Settings.Default.tax;

            Item_totalwt.Expression = "Item_Price * Item_Qty";

            DataColumn Item_Total = new DataColumn("Item_Total",
            Type.GetType("System.Decimal"));
            // "Item_Total" column is calculated as (Price * Qty + Tax)
            Item_Total.Expression = "Item_Price * Item_Qty + Item_Tax";

            saleslist.Columns.Add(Item_SKU);      //
            saleslist.Columns.Add(Item_Name);    // Add 4
            saleslist.Columns.Add(Item_Price);   // Columns
            saleslist.Columns.Add(Item_Qty);     // to
            saleslist.Columns.Add(Item_totalwt);
            saleslist.Columns.Add(Item_Tax);     // the
            saleslist.Columns.Add(Item_Total);   // Datatable

           
        }
Example #18
0
        void ReporteCliente()
        {
            MySqlCommand repcte  = new MySqlCommand(string.Format("select id_cte as 'Codigo', nombre1_cte 'Nombre', apellido1_cte as 'Apellido', tipo_auto as 'Tipo de Vehiculo' , marca_auto as 'Marca', modelo_auto as 'Modelo', matricula_auto as 'Placa' from tab_cliente inner join tab_automovil on idcliente_auto = id_cte"), csConexion.ObtenerConexion());
            try
            {
                MySqlDataAdapter msd = new MySqlDataAdapter();
                msd.SelectCommand = repcte;
                DataTable dbset = new DataTable();
                msd.Fill(dbset);
                BindingSource bsource = new BindingSource();

                bsource.DataSource = dbset;
                dtvRepCte.DataSource = bsource;
                msd.Update(dbset);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #19
0
        void mostrar_RepEmp()
        {
            MySqlCommand cmdRepEmp = new MySqlCommand(string.Format("select * from tab_repuesto"), csConexion.ObtenerConexion());
            try
            {
                MySqlDataAdapter msd = new MySqlDataAdapter();
                msd.SelectCommand = cmdRepEmp;
                DataTable dbset = new DataTable();
                msd.Fill(dbset);
                BindingSource bsource = new BindingSource();

                bsource.DataSource = dbset;
                dgvRepRep.DataSource = bsource;
                msd.Update(dbset);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #20
0
    //private List<object> lista = new List<object>();
    public MainWindow(MySqlConnection mySqlConnection)
        : base(Gtk.WindowType.Toplevel)
    {
        Build ();

        string sqlCommand = "SELECT * FROM articulo";
        MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter (sqlCommand, mySqlConnection);

        DataSet dataSet = new DataSet ();
        mySqlDataAdapter.Fill (dataSet);

        DataTable dataTable = dataSet.Tables [0];

        show (dataTable);

        DataRow dataRow = dataTable.Rows [0];
        dataRow ["nombre"] = DateTime.Now.ToString ();

        new MySqlCommandBuilder (mySqlDataAdapter);
        mySqlDataAdapter.Update (dataSet);
    }
Example #21
0
        private void wfServicio_Load(object sender, EventArgs e)
        {
            MySqlCommand tipserv = new MySqlCommand(string.Format("select id_tserv as 'codigo', descripcion_tserv as 'Tipo Servicio', precio_tserv as 'Precio' from tab_tiposervicio"), csConexion.ObtenerConexion());
            try
            {
                MySqlDataAdapter msd = new MySqlDataAdapter();
                msd.SelectCommand = tipserv;
                DataTable dbset = new DataTable();
                msd.Fill(dbset);
                BindingSource bsource = new BindingSource();

                bsource.DataSource = dbset;
                dgvTipoServicio.DataSource = bsource;
                msd.Update(dbset);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            //MUESTRA CLIENTE Y VEHICULO
            MySqlCommand muestrarep = new MySqlCommand(string.Format("select id_cte as 'Codigo', nombre1_cte 'Nombre', apellido1_cte as 'Apellido', tipo_auto as 'Tipo de Vehiculo' , marca_auto as 'Marca', matricula_auto as 'Placa' from tab_cliente inner join tab_automovil on idcliente_auto = id_cte"), csConexion.ObtenerConexion());
            try
            {
                MySqlDataAdapter msd = new MySqlDataAdapter();
                msd.SelectCommand = muestrarep;
                DataTable dbset = new DataTable();
                msd.Fill(dbset);
                BindingSource bsource = new BindingSource();

                bsource.DataSource = dbset;
                dgvClienteVehiculo.DataSource = bsource;
                msd.Update(dbset);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void loadNotifications(DateTime dt)
        {
            //try
            //{

            DBConnector dbcon = new DBConnector();

            if (dbcon.openConnection())
            {

                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = "SELECT idnotification AS Notification_ID, title AS Title, content AS Content, date AS Date, employee_name AS Employee, employee_number AS Employee_Number FROM notification WHERE date=@dt";
                cmd.Parameters.Add("@dt", MySql.Data.MySqlClient.MySqlDbType.Date).Value = dt;
                cmd.Connection = dbcon.connection;

                MySqlDataAdapter sda = new MySqlDataAdapter();
                sda.SelectCommand = cmd;
                DataTable dbdataset = new DataTable();
                sda.Fill(dbdataset);

                BindingSource bs = new BindingSource();
                bs.DataSource = dbdataset;
                dataGridView1.DataSource = bs;
                sda.Update(dbdataset);

                dbcon.closeConnection();

            }
            else
            {
                return;
            }

            //}
            //catch (MySqlException e)
            //{
            //int errorcode = e.Number;
            //}
        }
Example #23
0
        private void ViewBookDetails_Load(object sender, EventArgs e)
        {
            try {

                string query = "select * from library.book_database ;";
                MySqlConnection myConn = DB.GetDB();

                MySqlCommand cmdDataBase = new MySqlCommand (query, myConn);
                // MySqlDataReader myReader;

                MySqlDataAdapter sda = new MySqlDataAdapter ();
                sda.SelectCommand = cmdDataBase;
                DataTable dbDataset = new DataTable ();
                sda.Fill (dbDataset);
                BindingSource bsource = new BindingSource ();
                bsource.DataSource = dbDataset;
                dataGridView1.DataSource = bsource;
                sda.Update (dbDataset);

            } catch (Exception ex) {
                MessageBox.Show (ex.Message);
            }
        }
Example #24
0
        private void fillgridNoti()
        {
            //id = -1;
            //buttonDel.Visible = false;
            //buttonEdit.Visible = false;
            //buttonIns.Visible = false;
            //buttonCancel.Visible = false;
            DBConnect NewcConnection = new DBConnect();
            NewcConnection.dbConnection();
            MySqlCommand querysql = new MySqlCommand("Select * From noticias", DBConnect.db);

            try
            {
                MySqlDataAdapter dados = new MySqlDataAdapter();
                dados.SelectCommand = querysql;
                DataTable tabela = new DataTable();
                dados.Fill(tabela);
                BindingSource fonte = new BindingSource();
                fonte.DataSource = tabela;
                dataGridView1.DataSource = fonte;
               //this.dataGridView1.Columns[0].Visible = false;
               //this.dataGridView1.Columns[1].Visible = false;
               //dataGridView1.Columns[2].HeaderText = "Distrito";
               //dataGridView1.Columns[3].HeaderText = "Concelho";
                dados.Update(tabela);
                dataGridView1.AutoResizeColumns();
                dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            DBConnect.db.Close();
            //textBoxConc.Clear();
            //comboBox1.SelectedIndex = 0;
        }
Example #25
0
 /// <summary>
 ///使用MySqlDataAdapter批量更新数据
 /// </summary>
 /// <param name="connectionString">数据库连接字符串</param>
 /// <param name="table">数据表</param>
 public void BatchUpdate(string connectionString, DataTable table)
 {
     MySqlConnection connection = new MySqlConnection(connectionString);
     MySqlCommand command = connection.CreateCommand();
     command.CommandTimeout = CommandTimeOut;
     command.CommandType = CommandType.Text;
     MySqlDataAdapter adapter = new MySqlDataAdapter(command);
     MySqlCommandBuilder commandBulider = new MySqlCommandBuilder(adapter);
     commandBulider.ConflictOption = ConflictOption.OverwriteChanges;
     MySqlTransaction transaction = null;
     try
     {
         connection.Open();
         transaction = connection.BeginTransaction();
         //设置批量更新的每次处理条数
         adapter.UpdateBatchSize = BatchSize;
         //设置事物
         adapter.SelectCommand.Transaction = transaction;
         if (table.ExtendedProperties["SQL"] != null)
         {
             adapter.SelectCommand.CommandText = table.ExtendedProperties["SQL"].ToString();
         }
         adapter.Update(table);
         transaction.Commit();/////提交事务
     }
     catch (MySqlException ex)
     {
         if (transaction != null) transaction.Rollback();
         throw ex;
     }
     finally
     {
         connection.Close();
         connection.Dispose();
     }
 }
Example #26
0
        private void button1_Click(object sender, EventArgs e)
        {
            string constring = "datasource=localhost;port=3306;username=root;password=root";
            MySqlConnection conDataBase = new MySqlConnection(constring);
            // MySqlCommand cmdDataBase = new MySqlCommand("select * from Hospital.Order;", conDataBase);
            MySqlCommand cmdDataBase = new MySqlCommand("select id_order as '№ замовлення',id_medicine as'№ товару',id_client as'№ клієнта',data_of_receipt as'дата отримання замовлення',data_medicine_delivery as'дата видачі замовлення',price as'ціна замовлення' from Hospital.Order;", conDataBase);
            try
            {
                MySqlDataAdapter sda = new MySqlDataAdapter();
                sda.SelectCommand = cmdDataBase;
                DataTable dbdataset = new DataTable();
                sda.Fill(dbdataset);
                BindingSource bSource = new BindingSource();

                bSource.DataSource = dbdataset;
                dataGridView1.DataSource = bSource;
                sda.Update(dbdataset);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ManagerItemsGui"/> class.
 /// </summary>
 public ManagerItemsGui()
 {
     InitializeComponent();
     this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
     try
     {
         MySqlConnection MySqlConn = new MySqlConnection(Login.Connectionstring);
         MySqlConn.Open();
         string Query1 = ("SELECT itemid as `מקט פריט`, itemName as `שם פריט`,item_discription as `תיאור פריט` FROM item GROUP BY itemid");
         MySqlCommand MSQLcrcommand1 = new MySqlCommand(Query1, MySqlConn);
         MSQLcrcommand1.ExecuteNonQuery();
         MySqlDataAdapter mysqlDAdp = new MySqlDataAdapter(MSQLcrcommand1);
         //DataTable dt = new DataTable("jobs");
         dt.Clear();
         mysqlDAdp.Fill(dt);
         dataGrid1.ItemsSource = dt.DefaultView;
         mysqlDAdp.Update(dt);
         MySqlConn.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #28
0
        private void button1_Click(object sender, EventArgs e)
        {
            string constring = "datasource=localhost;port=3306;username=root;password=root";
            MySqlConnection conDataBase = new MySqlConnection(constring);
            //MySqlCommand cmdDataBase = new MySqlCommand("select * from Hospital.Medicine;", conDataBase);
            MySqlCommand cmdDataBase = new MySqlCommand("select id_medicine as'№ товару',maker as'Виробник',type_medicine as'Тип ліків',medicine_date as'Дата виготовлення',price as 'ціна',country as '№ країни' from Hospital.Medicine;", conDataBase);
            try
            {
                MySqlDataAdapter sda = new MySqlDataAdapter();
                sda.SelectCommand = cmdDataBase;
                DataTable dbdataset = new DataTable();
                sda.Fill(dbdataset);
                BindingSource bSource = new BindingSource();

                bSource.DataSource = dbdataset;
                dataGridView1.DataSource = bSource;
                sda.Update(dbdataset);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #29
0
        private void button1_Click(object sender, EventArgs e)
        {
            string constring = "datasource=localhost;port=3306;username=root;password=root";
            MySqlConnection conDataBase = new MySqlConnection(constring);
            //MySqlCommand cmdDataBase = new MySqlCommand("select * from car_rental.users;", conDataBase);
            MySqlCommand cmdDataBase = new MySqlCommand("select id_client as '№ клієнта',name_client as 'ПІБ',id_district as '№ області',id_street as '№ вулиці',house as'№ будинку',apartment as '№ квартири',phone as 'телефон' from Hospital.Client;", conDataBase);
            try
            {
                MySqlDataAdapter sda = new MySqlDataAdapter();
                sda.SelectCommand = cmdDataBase;
                DataTable dbdataset = new DataTable();
                sda.Fill(dbdataset);
                BindingSource bSource = new BindingSource();

                bSource.DataSource = dbdataset;
                dataGridView1.DataSource = bSource;
                sda.Update(dbdataset);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ManagerGeneralItemStagesGui"/> class.
        /// </summary>
        /// <param name="itemid">The itemid.</param>
        public ManagerGeneralItemStagesGui(string itemid)
        {
            //Login.close = 1;
            InitializeComponent();
            this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            this.itemID = itemid;
            try
            {
                MySqlConnection MySqlConn = new MySqlConnection(Login.Connectionstring);
                MySqlConn.Open();
                string Query1 = "select itemName from item where itemid='" + itemID + "'";
                MySqlCommand MSQLcrcommand1 = new MySqlCommand(Query1, MySqlConn);
                MSQLcrcommand1.ExecuteNonQuery();
                MySqlDataAdapter mysqlDAdp = new MySqlDataAdapter(MSQLcrcommand1);
                MySqlDataReader dr = MSQLcrcommand1.ExecuteReader();

                while (dr.Read())
                {
                    if (!dr.IsDBNull(0))
                    {
                        itemName = dr.GetString(0);
                    }

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

            type_comboBox.Items.Add("רישום");
            type_comboBox.Items.Add("בעבודה");
            type_comboBox.Items.Add("תיקון");
            type_comboBox.Items.Add("פסול");
            type_comboBox.Items.Add("גמר ייצור");
            type_comboBox.Items.Add("הסתיים");
            type_comboBox.SelectedIndex = 0;
            itemidlabel.Content = itemID;
            itemnamelabel.Content = itemName;

            try
            {
                MySqlConnection MySqlConn = new MySqlConnection(Login.Connectionstring);
                MySqlConn.Open();
                string Query1 = ("SELECT itemStageOrder as `מספר שלב`,stageName as `שם שלב` ,stage_discription as `תאור השלב`  FROM item WHERE itemid='" + itemID + "'  and itemStatus='רישום' ");
                MySqlCommand MSQLcrcommand1 = new MySqlCommand(Query1, MySqlConn);
                MSQLcrcommand1.ExecuteNonQuery();
                MySqlDataAdapter mysqlDAdp = new MySqlDataAdapter(MSQLcrcommand1);
                dt.Clear();
                mysqlDAdp.Fill(dt);
                dataGrid1.ItemsSource = dt.DefaultView;
                mysqlDAdp.Update(dt);
                MySqlConn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }