private void DBDeleteApptButton_Click(object sender, EventArgs e) { DataTable dd = new DataTable(); using (MySqlConnection cn = new MySqlConnection(Globals.connStr)) { cn.Open(); MySqlCommand cmd = new MySqlCommand("select * from appointment", cn); MySqlDataReader reader = cmd.ExecuteReader(); dd.Load(reader); cn.Close(); } try { int xyz = (int)dd.Rows[Globals.CurrApptIndex]["appointmentId"]; string Query = "delete from appointment where appointmentId= '" + xyz + "';"; MySqlConnection Conn2 = new MySqlConnection(Globals.connStr); MySqlCommand Command2 = new MySqlCommand(Query, Conn2); MySqlDataReader MyReader2; Conn2.Open(); MyReader2 = Command2.ExecuteReader(); MessageBox.Show("Data Deleted"); while (MyReader2.Read()) { } Conn2.Close(); } catch (Exception) { MessageBox.Show("Appointment could not be deleted", "Error"); } DataTable dt = new DataTable(); using (MySqlConnection cnl = new MySqlConnection(Globals.connStr)) { cnl.Open(); MySqlCommand cmld = new MySqlCommand("select appointmentId, customerId, type, start, end from appointment", cnl); MySqlDataReader reader = cmld.ExecuteReader(); dt.Load(reader); if (dt.Rows.Count > 0) { DashboardApptDGV.DataSource = dt; } cnl.Close(); } }
private void Patient_Load(object sender, EventArgs e) { panelNewPatient.Visible = false; panelEdit.Visible = false; try { string Query = "select Name from patient;"; MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); AutoCompleteStringCollection mycollection = new AutoCompleteStringCollection(); while (MyReader2.Read()) { mycollection.Add(MyReader2.GetString(0)); } textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource; textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; textBox1.AutoCompleteCustomSource = mycollection; textBox20.AutoCompleteSource = AutoCompleteSource.CustomSource; textBox20.AutoCompleteMode = AutoCompleteMode.SuggestAppend; textBox20.AutoCompleteCustomSource = mycollection; MyConn2.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { string Query = "select Name as 'Name',Email as 'Email',birth as 'Birth Date',Age,Gender,Blood_type as 'Blood Type',Phone as 'Phone',Address as 'Address',Disease as 'Disease' from patient;"; MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataAdapter MyAdapter = new MySqlDataAdapter(); MyAdapter.SelectCommand = MyCommand2; DataTable dTable = new DataTable(); MyAdapter.Fill(dTable); dataGridView1.DataSource = dTable; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void updat() { string Query = "select * from `Users`;"; MySqlConnection MyConn2 = new MySqlConnection(connect); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); this.listBox1.Items.Clear(); while (MyReader2.Read()) { this.listBox1.Items.Add(MyReader2.GetString("Login")); } MyConn2.Close(); }
private void button9_Click(object sender, EventArgs e) { if (textBox6.Text != "") { try { string MyConnection2 = "server=localhost;user id=root;password=;database=gallolowa_grocery"; string Query = ("select Customer_No as 'Customer No',Customer_Name as 'Customer Name',Customer_Cat as 'Customer Cat',Address as 'Address',Contact_No as 'Contact No',Sub_Balance as 'Balance' from customer_details WHERE Customer_Name LIKE '%" + textBox6.Text + "%';"); MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { } MyConn2.Close(); MySqlDataAdapter MyAdapter = new MySqlDataAdapter(); MyAdapter.SelectCommand = MyCommand2; DataTable dTable = new DataTable(); MyAdapter.Fill(dTable); dataGridView1.DataSource = dTable; foreach (DataGridViewColumn col in dataGridView1.Columns) { col.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; col.HeaderCell.Style.Font = new Font("Arial", 12F, FontStyle.Bold, GraphicsUnit.Pixel); col.DefaultCellStyle.Font = new Font("Arial", 13F, GraphicsUnit.Pixel); } MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { } MyConn2.Close(); } catch { MessageBox.Show("Invalid Name"); } } }
public void fillFields(string guid) { try { string MyConnection2 = "server=localhost; port=3306; database=akturegistracijadb; username=root; password=qwerty123; SslMode=none"; string query = "SELECT * FROM `aktudati` WHERE `GUID` = " + "'" + guid + "'"; MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { this.pas_nos_text.Text = MyReader2.GetString("Pasakuma Nosaukums"); this.pas_dat_text.Text = MyReader2.GetString("Pasakuma Datums"); this.vards_uzvards_text.Text = MyReader2.GetString("Vards Uzvards"); this.personas_kods_text.Text = MyReader2.GetString("Personas Kods"); this.mail_text.Text = MyReader2.GetString("Epasts"); this.tel_tex.Text = MyReader2.GetString("Telefona NR"); this.cena_text.Text = MyReader2.GetString("Biletes Cena"); this.id_text.Text = MyReader2.GetString("Bilesu ID"); this.bil_id_nr.Text = MyReader2.GetString("Bilesu Veidlapas Nummuri"); this.pirk_dat_text.Text = MyReader2.GetString("Pirkuma Datums"); this.ieg_viet_text.Text = MyReader2.GetString("Iegades vieta"); this.tirdz_punkta_text.Text = MyReader2.GetString("Tirdzniecibas vieta"); this.other_info_text.Text = MyReader2.GetString("Cits info"); this.konta_text.Text = MyReader2.GetString("Bankas Konts"); this.swift_text.Text = MyReader2.GetString("Swift Kods"); this.bank_nos_text.Text = MyReader2.GetString("Bankas Nosaukums"); this.guid_text.Text = MyReader2.GetString("GUID"); this.aizpildisanas_datums_text.Text = MyReader2.GetString("Aizpildisanas datums"); if (MyReader2.GetString("Statuss") == "Apstrādāts") { this.apstradats_checkbox.IsChecked = true; } else { this.apstradats_checkbox.IsChecked = false; } } MyReader2.Close(); } catch (Exception error) { MessageBox.Show(error.ToString()); } }
private void Btn_edit_Click(object sender, EventArgs e) { int selectedIndex = Cmb_id.SelectedIndex + 1; String error_nuevo = ""; obtenerIP(); String app = "3"; for (int counter = 0; counter < (Dgv_asignacion.Rows.Count) - 1; counter++) { try { //This is my connection string i have assigned the database file address path //This is my insert query in which i am taking input from the user through windows forms string Query = "insert into bd_seguridad.detalle_usuario_perfil(id_usuario,id_perfil) values('" + selectedIndex.ToString() + "','" + Convert.ToString(Dgv_asignacion[0, counter].Value) + "');"; //This is MySqlConnection here i have created the object and pass my connection string. OdbcConnection MyConn2 = new OdbcConnection(MyConnection2); //This is command class which will handle the query and connection object. OdbcCommand MyCommand2 = new OdbcCommand(Query, MyConn2); OdbcDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database. MessageBox.Show("Save Data"); connection.OpenConnection(); connection.InsertarRegistro("insert into bitacora(id_usuario,fecha_bitacora,hora_bitacora,accion_usuario,id_aplicacion,resultado_bitacora,error_bitacora,ip_pc) values((select U.id_usuario from usuario U where U.usuario ='" + Globales.nom_usuario + "'), sysdate(), now(), '" + Globales.sAccionE + "', '" + app + "','" + Globales.sExitoso + "', '" + Globales.sError + "','" + localIP + "')"); connection.CloseConnection(); while (MyReader2.Read()) { } MyConn2.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); s_error = "." + ex.Message + "."; String[] A = s_error.Split(new char[] { '\'' }, StringSplitOptions.RemoveEmptyEntries); foreach (string i in A) { error_nuevo += i; } connection.OpenConnection(); connection.InsertarRegistro("insert into bitacora(id_usuario,fecha_bitacora,hora_bitacora,accion_usuario,id_aplicacion,resultado_bitacora,error_bitacora,ip_pc) values((select U.id_usuario from usuario U where U.usuario ='" + Globales.nom_usuario + "'), sysdate(), now(), '" + Globales.sAccionE + "', '" + app + "','" + Globales.sExitoso_n + "', '" + error_nuevo + "','" + localIP + "')"); connection.CloseConnection(); } } }
private void button2_Click(object sender, EventArgs e) { try { string MyConnection2 = "Data Source=HGDLAPLEYVALC\\SQLEXPRESS;" + "Initial Catalog=Northwind;" + "Integrated Security=True;"; string Query = "update Customers set CustomerID='" + this.ID.Text + "',CompanyName='" + this.Company.Text + "',ContactName='" + this.Contact.Text + "',ContactTitle='" + this.Title.Text + "',Address='" + this.Address.Text + "',City='" + this.City.Text + "',Region='" + this.Region.Text + "',PostalCode='" + this.CP.Text + "',Country='" + this.Country.Text + "',Phone='" + this.Phone.Text + "',Fax='" + this.Fax.Text + "' where CustomerID='" + this.ID.Text + "';"; SqlConnection MyConn2 = new SqlConnection(MyConnection2); SqlCommand MyCommand2 = new SqlCommand(Query, MyConn2); SqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); MessageBox.Show("Data Updated"); while (MyReader2.Read()) { } MyConn2.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button1_Click(object sender, EventArgs e) { //String query = "INSERT INTO add (title,description,price) VALUES (@title,@description,@price)"; //using (SqlCommand command = new SqlCommand(query, con)) //{ // command.Parameters.AddWithValue("@title", textBox1.Text); // command.Parameters.AddWithValue("@description", richTextBox1.Text); // command.Parameters.AddWithValue("@price", textBox2.Text); // SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-O8UDH05;Initial Catalog=APRO;Integrated Security=True"); // con.Open(); // int result = command.ExecuteNonQuery(); // Check Error // if (result < 0) // Console.WriteLine("Error inserting data into Database!"); // con.Close(); //} if (textBox1.Text != "" && textBox2.Text != "") { try { //This is my connection string i have assigned the database file address path string MyConnection2 = "Data Source=DESKTOP-O8UDH05;Initial Catalog=APRO;Integrated Security=True"; //This is my insert query in which i am taking input from the user through windows forms string Query = "insert into sell (title,descrip,price,category) values('" + textBox1.Text + "','" + richTextBox1.Text + "','" + textBox2.Text + "','" + comboBox1.Text + "');"; //This is MySqlConnection here i have created the object and pass my connection string. SqlConnection MyConn2 = new SqlConnection(MyConnection2); //This is command class which will handle the query and connection object. SqlCommand MyCommand2 = new SqlCommand(Query, MyConn2); SqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database. MessageBox.Show("Ad Inserted Successfully"); while (MyReader2.Read()) { } MyConn2.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void bunifuThinButton21_Click(object sender, EventArgs e) { try { string MyConnection2 = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\wishwa\\Documents\\mainfuntionsdb.mdf;Integrated Security=True;Connect Timeout=30"; SqlConnection MyConn2 = new SqlConnection(MyConnection2); SqlCommand check_User_Name = new SqlCommand("SELECT COUNT(*) FROM site_controle WHERE project_number='" + this.pronumsitcontxt.Text.Trim() + "';", MyConn2); check_User_Name.Parameters.AddWithValue("number", number.Text); MyConn2.Open(); int UserExist = (int)check_User_Name.ExecuteScalar(); MyConn2.Close(); if (UserExist > 0) { string Query = "delete from site_controle where project_number='" + this.pronumsitcontxt.Text.Trim() + "';"; SqlCommand MyCommand2 = new SqlCommand(Query, MyConn2); SqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); MessageBox.Show("Data Deleted"); while (MyReader2.Read()) { } string Query1 = "select * from site_controle;"; string MyConnection21 = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\wishwa\\Documents\\mainfuntionsdb.mdf;Integrated Security=True;Connect Timeout=30"; SqlConnection mycon1 = new SqlConnection(@MyConnection21); SqlCommand sqcmnd1 = new SqlCommand(Query1, mycon1); SqlDataReader dr1; SqlDataAdapter MyAdapter = new SqlDataAdapter(); MyAdapter.SelectCommand = sqcmnd1; DataTable dTable = new DataTable(); MyAdapter.Fill(dTable); bunifuCustomDataGrid1.DataSource = dTable; MyConn2.Close(); sitecontroltxtclear(); } else { MessageBox.Show("Item is't found in db"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void adddatabutton1_Click(object sender, EventArgs e) { string s = moneytextBox2.Text; int x = int.Parse(s); //MessageBox.Show(x.ToString()); try { string MyConnection2 = "datasource=localhost; username=root;password=; database=bank"; string query1 = "SELECT name,total_taka FROM " + idtextBox1.Text + " WHERE(total_taka-" + x + ")=total_taka "; MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand3 = new MySqlCommand(query1, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand3.ExecuteReader(); //MessageBox.Show("Save Data"); while (MyReader2.Read()) { } MyConn2.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } if (idtextBox1.Text == "") { MessageBox.Show("Error!"); } else { MySqlConnection con = new MySqlConnection("datasource=localhost; username=root;password=; database=bank"); con.Open(); MySqlCommand cmd; cmd = con.CreateCommand(); cmd.CommandText = "SELECT *FROM " + idtextBox1.Text + ""; MySqlDataReader sdr = cmd.ExecuteReader(); DataTable dtrecord = new DataTable(); dtrecord.Load(sdr); dataGridView1.DataSource = dtrecord; dataGridView1.Visible = true; } idtextBox1.Clear(); moneytextBox2.Clear(); idtextBox1.Focus(); }
private void button2_Click(object sender, EventArgs e) { textBox3.Text = GetMD5(textBox3.Text); try { //This is my connection string i have assigned the database file address path string MyConnection2 = "datasource=localhost;port=3306;username=root;password=;database=newdatabase"; //This is my update query in which i am taking input from the user through windows forms and update the record. string Query = "update kullanici set idkullanici='" + this.textBox1.Text + "',kullaniciAdi='" + this.textBox2.Text + "', kullaniciSifre='" + this.textBox3.Text + "' where idkullanici='" + this.textBox1.Text + "';"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); if (textBox1.Text == "0" || textBox1.Text == null) { MessageBox.Show("Lütfen geçerli bir değer giriniz."); } else { MessageBox.Show("Veri başarılı bir şekilde güncellendi."); } while (MyReader2.Read()) { } MyConn2.Close();//Connection closed here } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void load_combo_disease_namee() { try { string Query = "select distinct disease_name from test_name where disease_type='" + comboDiseaseType.SelectedItem.ToString() + "';"; MySqlCommand MyCommand2 = new MySqlCommand(Query, conn); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { string name = MyReader2.GetString(0); this.comboDiseaseName.Items.Add(name); } MyReader2.Close(); } catch {} }
private void button3_Click_1(object sender, EventArgs e) { string MyConnection2 = "server=localhost;user id=root;password=;database=gallolowa_grocery"; string Query = ("update customer_details set Balance_Limit = '" + this.textBox4.Text + "' WHERE Customer_No = '" + this.textBox8.Text + "'"); MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); MessageBox.Show("Update..!"); while (MyReader2.Read()) { } MyConn2.Close(); }
private void button12_Click(object sender, EventArgs e) { try { string MyConnection2 = "server=localhost;user id=root;password=;database=gallolowa_grocery"; string Query = ("select Item_No as 'Item No',Item_Name as 'Item Name',Dealer as 'Dealer',Stock_Code as 'Stock Code',Purchase_Stock as 'Purchase_Stock',Purchase_Price as 'Purchase_Price',Unit_Price as 'Unit_Price',Best_Price as 'Best_Price',Ex_Date as 'Ex_Date',Current_Stock as 'Current_Stock',(Purchase_Stock-Current_Stock) as 'Sell_Stock',Tax as 'Tax',Discount as 'Discount',S_Name as 'S_Name' from stock_details"); MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { } MyConn2.Close(); MySqlDataAdapter MyAdapter = new MySqlDataAdapter(); MyAdapter.SelectCommand = MyCommand2; DataTable dTable = new DataTable(); MyAdapter.Fill(dTable); dataGridView1.DataSource = dTable; foreach (DataGridViewColumn col in dataGridView1.Columns) { col.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; col.HeaderCell.Style.Font = new Font("Arial", 12F, FontStyle.Bold, GraphicsUnit.Pixel); col.DefaultCellStyle.Font = new Font("Arial", 13F, GraphicsUnit.Pixel); } MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { } MyConn2.Close(); } catch { } }
void load_doctor_name() { try { string Query = "select name from doctor;"; MySqlCommand MyCommand2 = new MySqlCommand(Query, conn); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { string name = MyReader2.GetString(0); this.comboboxDoctorName.Items.Add(name); } MyReader2.Close(); } catch { } }
void load_blood_group() { try { string Query = "select * from blood_group;"; MySqlCommand MyCommand2 = new MySqlCommand(Query, conn); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { string name = MyReader2.GetString(0); comboboxBloodGroup.Items.Add(name); } MyReader2.Close(); } catch { } }
void load_disease() { try { string Query = "select distinct disease_name from medicine_name;"; MySqlCommand MyCommand2 = new MySqlCommand(Query, conn); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { string name = MyReader2.GetString(0); comboboxDisease.Items.Add(name); } MyReader2.Close(); } catch { } }
private void button1_Click(object sender, EventArgs e) { string text = textBox1.Text; string text1 = textBox2.Text; if (String.IsNullOrEmpty(text)) { MessageBox.Show("Please enter the movie"); return; } if (String.IsNullOrEmpty(text1)) { MessageBox.Show("Please enter the time of movie"); return; } try { //This is my connection string i have assigned the database file address path string MyConnection2 = "server=localhost;uid=root;pwd=;database=movies"; //This is my insert query in which i am taking input from the user through windows forms string Query = "INSERT into movie1(movieName1,movieTime1) values('" + this.textBox1.Text + "','" + this.textBox2.Text + "');"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); //This is command class which will handle the query and connection object. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database. MessageBox.Show("Movie saved!"); while (MyReader2.Read()) { } MyConn2.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } Form1 form1 = new Form1(); form1.buttonUpdate(); Form2 form2 = new Form2(); }
private void flatButton1_Click(object sender, EventArgs e) { if (txtuser.Text != "") { if (txtpass.Text != "") { try { string MyConnection2 = "server = remotemysql.com; user id = OFwjckvGPT; password = JfSCc4x5oz; database = OFwjckvGPT"; string Query = "INSERT INTO `users` (`id`, `username`, `password`) VALUES (NULL, '" + txtuser.Text + "', '" + txtpass.Text + "')"; MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); MessageBox.Show("Succesfully registered in: user:'******'with password: '******'"); while (MyReader2.Read()) { } MyConn2.Close(); MySqlConnection connection = new MySqlConnection("server = remotemysql.com; user id = OFwjckvGPT; password = JfSCc4x5oz; database = OFwjckvGPT"); MySqlDataAdapter adapter = new MySqlDataAdapter("select * from users", connection); connection.Open(); DataSet ds = new DataSet(); adapter.Fill(ds, "users"); dataGridView1.DataSource = ds.Tables["users"]; connection.Close(); txtuser.Text = ""; txtpass.Text = ""; } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Please fill all of data!", "SadSploit - ERROR", MessageBoxButtons.OK, MessageBoxIcon.None); } } else { MessageBox.Show("Please fill all of data!", "SadSploit - ERROR", MessageBoxButtons.OK, MessageBoxIcon.None); } }
private void button2_Click(object sender, EventArgs e) { string rowIndex1 = dataGridView1.CurrentRow.Cells["Date"].Value.ToString(); string rowIndex2 = dataGridView1.CurrentRow.Cells["Time"].Value.ToString(); string rowIndex3 = dataGridView1.CurrentRow.Cells["Location"].Value.ToString(); string rowIndex4 = dataGridView1.CurrentRow.Cells["Organizer"].Value.ToString(); string rowIndex5 = dataGridView1.CurrentRow.Cells["OrganizerContactNo"].Value.ToString(); try { string MyConnection2 = "server = localhost; user id = root; database=premonexbc"; string Query = "delete from event where Time='" + rowIndex2 + "' AND Location='" + rowIndex3.ToString() + "' AND Organizer='" + rowIndex4 + "'AND OrganizerContactNo='" + rowIndex5 + "' "; MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); MessageBox.Show("Event Deleted"); while (MyReader2.Read()) { } MyConn2.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { string MyConnection2 = "server=localhost;user id=root;database=premonexbc"; string Query = "select * from event"; MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataAdapter MyAdapter = new MySqlDataAdapter(); MyAdapter.SelectCommand = MyCommand2; DataTable dTable = new DataTable(); MyAdapter.Fill(dTable); dataGridView1.DataSource = dTable; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void iconButton2_Click(object sender, EventArgs e) { if (MessageBox.Show("Deseas Guardar Cambios?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { if (textBox2.Text.Trim() == textBox3.Text.Trim()) { try { idLocRemv = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); } catch (Exception) { MessageBox.Show("Selesione la casilla bien ", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } try { //This is my connection string i have assigned the database file address path // string MyConnection2 = "server=127.0.0.1; database=enfermeria_utem; Uid=root; pwd=;SslMode = none"; //This is my update query in which i am taking input from the user through windows forms and update the record. string Query = "UPDATE `usuarios` SET `nombre_usuario`='" + this.textBox1.Text.Trim() + "',`contraseña`='" + textBox2.Text.Trim() + "' where nombre_usuario='" + idLocRemv + "';"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { } MyConn2.Close();//Connection closed here show_usuarios(); clear(); MessageBox.Show("Usuario Actualisado Con Exito ", "", MessageBoxButtons.OK, MessageBoxIcon.None); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("las contraseñas no coinsiden", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public Candle[] GetThreeDataFromDB(string code, int date, int dayCount) { // if dayCount == 1 then realtime // use offset(129) to idx when set to threeArray Candle[] threeArray = new Candle[Constants.DAY_CANDLE_COUNT * dayCount]; try { string Query = "select date, time, start_price, end_price, high_price, low_price, volumn, avg_5, avg_20, avg_120 from three where code=@val1 and date >= @val2 order by date asc, time asc limit @val3;"; MySqlConnection MyConn2 = GetConnection(); MySqlCommand cmd = new MySqlCommand(Query, MyConn2); cmd.Parameters.AddWithValue("@val1", code); cmd.Parameters.AddWithValue("@val2", date); cmd.Parameters.AddWithValue("@val3", Constants.DAY_CANDLE_COUNT * dayCount); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = cmd.ExecuteReader(); int i = 0; while (MyReader2.Read()) { Candle entity = new Candle(); entity.code = code; entity.date = MyReader2.GetInt32(0); entity.time = MyReader2.GetInt32(1); entity.startprice = MyReader2.GetInt32(2); entity.endprice = MyReader2.GetInt32(3); entity.highprice = MyReader2.GetInt32(4); entity.lowprice = MyReader2.GetInt32(5); entity.volume = MyReader2.GetInt32(6); entity.avg5 = MyReader2.GetInt32(7); entity.avg20 = MyReader2.GetInt32(8); entity.avg120 = MyReader2.GetInt32(9); threeArray[i] = entity; i += 1; } MyConn2.Close(); } catch (Exception e) { Console.Write(e); } return(threeArray); }
private void Zmien_date() { try { string MyConnection2 = "datasource=localhost;port=3306;username=root;password=root;database=bd2"; foreach (char c in nowaData_ZmianaTerminu.Text) { if (!char.IsDigit(c)) { MessageBox.Show("Podano bledny format danych"); } czyPoprawne = false; } foreach (char c in NumerBiletu_TextBox.Text) { if (!char.IsDigit(c)) { MessageBox.Show("Podano bledny format danych"); } czyPoprawne = false; } string Query = "UPDATE Polaczenia SET Data = '" + nowaData_ZmianaTerminu.Text + "' WHERE idPolaczenia = " + NumerBiletu_TextBox.Text; MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); MessageBox.Show(Query); while (MyReader2.Read()) { } MyConn2.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button32_Click(object sender, EventArgs e) //save btn { try { string Query22 = "UPDATE donor SET Name='" + this.textBox2.Text + "',Age='" + this.textBox3.Text + "',Weight='" + this.textBox4.Text + "',Gender='" + this.textBox5.Text + "',Blood='" + this.comboBox1.Text + "',Last_donate='" + this.dateTimePicker1.Value.ToString("yyyy-M-d") + "',Phone='" + this.textBox7.Text + "',Address='" + this.textBox8.Text + "',Disease='" + this.textBox9.Text + "' where Name = '" + this.label14.Text + "'"; MySqlCommand MyCommand2 = new MySqlCommand(Query22, MyConn); MySqlDataReader MyReader2; MyConn.Open(); MyReader2 = MyCommand2.ExecuteReader(); //MessageBox.Show("Save Successfully!"); textBox2.Visible = false; textBox3.Visible = false; textBox4.Visible = false; textBox5.Visible = false; textBox7.Visible = false; textBox8.Visible = false; textBox9.Visible = false; comboBox1.Visible = false; dateTimePicker1.Visible = false; button17.Visible = true; button18.Visible = true; button19.Visible = true; button20.Visible = true; button21.Visible = true; button22.Visible = true; button23.Visible = true; button24.Visible = true; button25.Visible = true; while (MyReader2.Read()) { } MyConn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } MySqlDataAdapter sda = new MySqlDataAdapter("select Name,Age,Weight,Gender,Blood,Last_donate,Phone,Address,Disease from donor where Email ='" + label101.Text + "'", MyConn); DataTable dt = new DataTable(); sda.Fill(dt); try { label14.Text = dt.Rows[0]["Name"].ToString(); label15.Text = dt.Rows[0]["Age"].ToString(); label16.Text = dt.Rows[0]["Weight"].ToString(); label17.Text = dt.Rows[0]["Gender"].ToString(); label18.Text = dt.Rows[0]["Blood"].ToString(); label20.Text = dt.Rows[0]["Last_Donate"].ToString(); label19.Text = dt.Rows[0]["Phone"].ToString(); label21.Text = dt.Rows[0]["Address"].ToString(); label22.Text = dt.Rows[0]["Disease"].ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//insert db private void insertbd(string var1, string var2, string var4, string var5, string var6, string var7, string var8, string var9) { string MyConnection2 = "server=localhost;uid=root;" + "pwd=;database=prueba;SslMode=none"; string Query = "insert into prueba.inicial(item,qty,lot,hu,status,fecha,tipo,color) values ('" + var1 + "'," + "'" + var2 + "', " + "'" + var4 + "', " + "'" + var5 + "'," + "'" + var6 + "'," + "'" + var7 + "'," + "'" + var8 + "'," + "'" + var9 + "');"; MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); MessageBox.Show("Save Data"); while (MyReader2.Read()) { } MyConn2.Close(); }
private void button11_Click(object sender, EventArgs e) { string MyConnection2 = "server=localhost;user id=root;password=;database=gallolowa_grocery"; string Query = "insert into combo1(Sub_Category) values('" + this.textBox10.Text + "');"; MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MySqlParameter Parameters = new MySqlParameter(); MyConn2.Open(); // MyCommand2.Parameters.Add(new MySqlParameter("@IMG", imageBt)); MyReader2 = MyCommand2.ExecuteReader(); MessageBox.Show("Add successfully!"); while (MyReader2.Read()) { } MyConn2.Close(); }
private void comboBoxDisc2_SelectedIndexChanged(object sender, EventArgs e) { string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; MySqlConnection connection = new MySqlConnection(Conexao); connection.Open(); string disciplina2 = comboBoxDisc2.SelectedItem.ToString(); string query2 = "select * from Disciplina where Disciplina = '" + disciplina2 + "' "; MySqlCommand MyCommand2 = new MySqlCommand(query2, connection); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { textBoxIDDisc2.Text = MyReader2["ID_Disciplina"].ToString(); } connection.Close(); }
private void button1_Click(object sender, EventArgs e) { string año, mes, dia, fecha; año = dateTimePicker1.Value.Year.ToString(); mes = dateTimePicker1.Value.Month.ToString(); dia = dateTimePicker1.Value.Day.ToString(); fecha = año + "/" + mes + "/" + dia; string sql = @"SELECT DATEDIFF(fecha_prevista_de_recibido, '" + fecha + "') FROM `ordenesdecompra` WHERE id_oc = '" + this.comboBox1.Text + "'"; OdbcConnection conector = new OdbcConnection("Driver ={ MySQL ODBC 3.51 Driver }; Dsn=hotelsancarlos; UID=root; PWD=1234; Database=hotelsancarlosv2; "); conector.Open(); OdbcCommand cmd = new OdbcCommand(sql, conector); int fecha2 = Convert.ToInt32(cmd.ExecuteScalar()); int dias = Math.Abs(fecha2); MessageBox.Show("DIAS:" + dias); try { //This is my connection string i have assigned the database file address path string MyConnection2 = "Driver ={ MySQL ODBC 3.51 Driver }; Dsn=hotelsancarlos; UID=root; PWD=1234; Database=hotelsancarlosv2; "; //This is my insert query in which i am taking input from the user through windows forms string Query = "insert into hotelsancarlosv2.controldemoras(id_oc,fecha_entregada,demora) values('" + this.comboBox1.Text + "','" + fecha + "','" + dias + "');"; //This is MySqlConnection here i have created the object and pass my connection string. OdbcConnection MyConn2 = new OdbcConnection(MyConnection2); //This is command class which will handle the query and connection object. OdbcCommand MyCommand2 = new OdbcCommand(Query, MyConn2); OdbcDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database. MessageBox.Show("DATOS GUARDADOS"); while (MyReader2.Read()) { } MyConn2.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void gttotbtn_Click(object sender, EventArgs e) { String sq1 = "SELECT Comulative_balance FROM ds WHERE Emp_Number = '" + textBox42.Text.ToString() + "';"; float val1 = float.Parse(textBox48.Text.Trim(), CultureInfo.InvariantCulture.NumberFormat); float val2 = float.Parse(textBox52.Text.Trim(), CultureInfo.InvariantCulture.NumberFormat); float tot = val1 - val2; textBox53.Text = tot.ToString(); try { string MyConnection2 = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\wishwa\\Documents\\mainfuntionsdb.mdf;Integrated Security=True;Connect Timeout=30"; SqlConnection MyConn2 = new SqlConnection(@MyConnection2); MyConn2.Open(); SqlCommand check_User_Name = new SqlCommand("SELECT COUNT(*) FROM ds WHERE Emp_Number='" + this.textBox42.Text.Trim() + "';", MyConn2); check_User_Name.Parameters.AddWithValue("Emp_Number", textBox42.Text); int UserExist = (int)check_User_Name.ExecuteScalar(); MyConn2.Close(); if (UserExist > 0) { SqlCommand MyCommand2 = new SqlCommand(sq1, MyConn2); SqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); MessageBox.Show("Data Updated"); while (MyReader2.Read()) { float val5 = float.Parse(MyReader2["Comulative_balance"].ToString(), CultureInfo.InvariantCulture.NumberFormat); float val6 = float.Parse(textBox53.Text.Trim(), CultureInfo.InvariantCulture.NumberFormat); cumbtn.Text = (val5 + val6).ToString(); } } else { cumbtn.Text = this.textBox53.Text; } } catch (Exception ex) { } }
private void dataGridViewEventos_SelectionChanged(object sender, EventArgs e) { if (dataGridViewEventos.SelectedCells.Count <= 0) { return; } string select = dataGridViewEventos.SelectedCells[0].Value.ToString(); this.dataGridViewEventos.Columns["ID_Evento"].Visible = false; string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; MySqlConnection connection = new MySqlConnection(Conexao); connection.Open(); string query = "select * from Evento where ID_Evento = '" + select + "' "; MySqlCommand MyCommand = new MySqlCommand(query, connection); MySqlDataReader MyReader; MyReader = MyCommand.ExecuteReader(); while (MyReader.Read()) { textBoxDt_Inicio.Text = MyReader["Dt_Inicio"].ToString(); textBoxDt_Final.Text = MyReader["Dt_Final"].ToString(); textBoxID_Disc2.Text = MyReader["ID_Disciplina"].ToString(); textBoxDesc_Agenda.Text = MyReader["Descricao"].ToString(); } connection.Close(); connection.Open(); string ID_Disc = textBoxID_Disc2.Text; string query2 = "select Disciplina from Disciplina where ID_Disciplina = '" + ID_Disc + "' ;"; MySqlCommand MyCommand2 = new MySqlCommand(query2, connection); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { textBoxDisciplina.Text = MyReader2["Disciplina"].ToString(); } connection.Close(); }