public MySqlDataReader executarConsulta(MySqlCommand cmm) { conectar(); cmm.Connection = conn; try { dr = cmm.ExecuteReader(); } catch (MySqlException ex) { dr.Dispose(); throw ex; } return dr; }
private void updateData() { try { db.sql = $"select `date_create`, `transaction_name`,`cash`,`comment` from `income_transaction` where `income_id` = '{month + year}'"; db.addCMD(); MySql.Data.MySqlClient.MySqlDataReader r = db.cmd.ExecuteReader(); bool flag = false; while (r.Read()) { flag = true; int cash = r.GetInt32(2); ListViewItem item = new ListViewItem(r.GetString(0)); for (int i = 1; i < r.FieldCount; i++) { item.SubItems.Add(r.GetValue(i).ToString()); } cashDetailListView.Items.Add(item); if (r.GetString(1) == "member payment") { memberIncome += cash; } else { otherIncome += cash; } allIncome += cash; tt++; } if (!flag) { MessageBox.Show("NO ITEM HERE"); } r.Dispose(); db.disposeCmd(); cashDetailTotalTbox.Text = allIncome.ToString("N"); cashDetailMemberIncomeTbox.Text = memberIncome.ToString("N"); cashDetailTransTbox.Text = tt.ToString(); cashDetailOtherTbox.Text = otherIncome.ToString("N"); monthTbox.Text = $"{month} {year}"; } catch (MySqlException err) { MessageBox.Show(err.Message, err.Number.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void JsonSend(string[] jSon) { if (DataToConnect == null || !_isEnabled) return; try { if (jSon.Length != 4) throw new Exception("This is not property jSon data."); //Prepare a new _connection _connection = new MySqlConnection(DataToConnect); //open mysql client _connection.Open(); string latin1Command1 = UTF8toLatin ($"insert into dane(IDUrzadzenia, dane, czas, data) values('{jSon[0]}','{jSon[1]}','{jSon[2]}','{jSon[3]}');"); _categoriesCommand = new MySqlCommand(latin1Command1, _connection); _reader = _categoriesCommand.ExecuteReader(); while (_reader.Read()) { } _reader.Dispose(); SendMessage("Log sent to Remote database."); } catch { SendMessage("Can't connect to remote database! Check all."); } }
public static string ReadTotal(string query,string row,string morequery = null) { try{ if (con.State.ToString() != "Open") con.Open(); using(con){ using(cmd = new MySqlCommand(query, con)){ rdr = cmd.ExecuteReader(); if(rdr.HasRows) while (rdr.Read()) Debug.Log(rdr[row].ToString()); rdr.Dispose(); } } } catch (Exception ex){ return ex.ToString(); } return ""; }
// Read all entries from the table void ReadEntries() { string query = string.Empty; if (_GameItems == null) _GameItems = new List<data>(); if (_GameItems.Count > 0) _GameItems.Clear(); // Error trapping in the simplest form try { query = "SELECT * FROM view_demo"; if (con.State.ToString() != "Open") con.Open(); using (con) { using (cmd = new MySqlCommand(query, con)) { rdr = cmd.ExecuteReader(); if (rdr.HasRows) while (rdr.Read()) { data itm = new data(); itm.UID = int.Parse(rdr["iddemo_table"].ToString()); itm.ID = rdr["ID"].ToString(); itm.levelname = rdr["levelname"].ToString(); itm.Name = rdr["Name"].ToString(); itm.objectType = rdr["objectType"].ToString(); itm.posx = float.Parse(rdr["posx"].ToString()); itm.posy = float.Parse(rdr["posy"].ToString()); itm.posz = float.Parse(rdr["posz"].ToString()); itm.tranx = float.Parse(rdr["tranx"].ToString()); itm.trany = float.Parse(rdr["trany"].ToString()); itm.tranz = float.Parse(rdr["tranz"].ToString()); _GameItems.Add(itm); } rdr.Dispose(); } } } catch (Exception ex) { Debug.Log(ex.ToString()); } finally { } }
void LogIn(NetworkMessage netMsg, InfoMessage msg) { bool loggedIn = false; string query = "SELECT * FROM shogi.players WHERE players_email = \"" + msg.email + "\""; if (con.State.ToString () != "Open") con.Open (); using (con) { using (cmd = new MySqlCommand (query, con)) { rdr = cmd.ExecuteReader(); if (rdr.HasRows) { rdr.Read (); if (msg.password == rdr["players_password"].ToString ()) { incomeMessages.text += netMsg.conn.address + " logged in as " + msg.email + "\n"; loggedIn = true; } else incomeMessages.text += netMsg.conn.address + " failed logging in for wrong password " + msg.password + "\n"; } else incomeMessages.text += netMsg.conn.address + " failed logging in for no entry " + msg.email + "\n"; rdr.Dispose (); } string queryIP = "UPDATE shogi.players SET players_ip = \"" + netMsg.conn.address + "\" WHERE players_email = \"" + msg.email + "\""; if (loggedIn) { using (cmd = new MySqlCommand (queryIP, con)) cmd.ExecuteNonQuery (); msg.goal = "loggedin"; NetworkServer.SendToClient(netMsg.conn.connectionId, MyMsgType.Info, msg); } } }
public MySqlDataReader executarConsulta(string pSql) { conectarDB(); cmm = new MySqlCommand(pSql, conn); try { dr = cmm.ExecuteReader(); } catch (MySqlException ex) { dr.Dispose(); throw ex; } return dr; }
/// <summary> /// Load gamestate from current player /// </summary> /// <param name="result"></param> public void LoadGameState(MySqlDataReader result) { result.Read(); player.Gold = result.GetInt32(1); this.turn = result.GetInt32(2); List<Cargo> clist = player.GetPlayersCargoList(); int i = 3; foreach (Cargo cargo in player.GetPlayersCargoList()) { cargo.Amount = result.GetInt32(i); i++; } foreach (Port port in portList) { i=12; foreach (Cargo cargo in port.GetPortsCargoList()) { cargo.Price = result.GetInt32(i); i++; } } result.Dispose(); }