private void sure_Click(object sender, EventArgs e) { DBConn.Open(); MySQLCommand DBComm = new MySQLCommand("select * from `parkingsystem`.`manager`", DBConn); MySQLCommand firstCmd = new MySQLCommand("set names big5", DBConn); firstCmd.ExecuteNonQuery(); MySQLDataReader DBReader = DBComm.ExecuteReaderEx(); bool error = true; DBReader.Read(); do { string id = ("" + DBReader.GetValue(0)); //id string passoord = ("" + DBReader.GetValue(2)); //password string enter = System.DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss"); if (tB_id.Text == id && tB_password.Text == passoord) { error = false; MySQLCommand DBCom = new MySQLCommand("INSERT INTO `parkingsystem`.`login_record` (`date`,`id`,`result`)VALUES ('" + enter + "','" + tB_id.Text + "','" + "帳密正確" + "');", DBConn); MySQLDataReader DBReader1 = DBCom.ExecuteReaderEx(); this.Close(); } } while (DBReader.Read()); if (error) { MessageBox.Show("登錄檔作業失敗!! =" + "\r\n" + "帳號或密碼有錯!請再確認"); } }
public void CheckPassword() { // 檢查帳密正確性 // 權限設定還沒寫 DBConn.Open(); MySQLCommand DBComm = new MySQLCommand("select * from `RFID_Project`.`user`", DBConn); MySQLCommand firstCmd = new MySQLCommand("set names big5", DBConn); firstCmd.ExecuteNonQuery(); MySQLDataReader DBReader = DBComm.ExecuteReaderEx(); bool error = true; DBReader.Read(); do { string id = ("" + DBReader.GetValue(0)); //id string passoord = ("" + DBReader.GetValue(1)); //password string enter = System.DateTime.Now.ToString("yyyy/MM/dd/ HH:mm:ss"); if (tB_Id.Text == id && tB_Password.Text == passoord) { error = false; MySQLCommand DBCom = new MySQLCommand("INSERT INTO `RFID_Project`.`login_record` (`date`,`id`,`result`)VALUES ('" + enter + "','" + tB_Id.Text + "','" + "success" + "');", DBConn); //登錄記錄 MySQLDataReader DBReader1 = DBCom.ExecuteReaderEx(); this.DialogResult = DialogResult.OK; this.Close(); } } while (DBReader.Read()); if (error) { MessageBox.Show("登錄檔作業失敗!! " + "\r\n" + "帳號或密碼有錯!請再確認"); } DBConn.Close(); }
private void timer4_Tick(object sender, EventArgs e) { DBConn.Open(); MySQLCommand DBComm = new MySQLCommand("select * from `parkingsystem`.`login_record`", DBConn); MySQLCommand firstCmd = new MySQLCommand("set names big5", DBConn); firstCmd.ExecuteNonQuery(); MySQLDataReader DBReader = DBComm.ExecuteReaderEx(); DBReader.Read(); do { if (DBReader.GetString(2) == "帳密正確") { tSB_Exit.Enabled = true; tSB_search.Enabled = true; TSMI_help.Enabled = true; tabControl1.Enabled = true; MySQLCommand DBCom = new MySQLCommand("UPDATE `parkingsystem`.`login_record` SET `result` = '成功登入' WHERE CONVERT( `login_record`.`date` USING utf8 ) = '" + DBReader.GetString(0) + "' LIMIT 1 ;", DBConn); MySQLDataReader DBReader1 = DBCom.ExecuteReaderEx(); timer4.Enabled = false; break; } } while (DBReader.Read()); DBConn.Close(); }
public void Find() { //在異常事件記錄抓未處理資料出來 DBConn.Open(); MySQLCommand DBComm = new MySQLCommand("select * from `RFID_Project`.`event_record`", DBConn); MySQLCommand firstCmd = new MySQLCommand("set names big5", DBConn); firstCmd.ExecuteNonQuery(); MySQLDataReader DBReader = DBComm.ExecuteReaderEx(); while (DBReader.Read()) { if (DBReader.GetString(5) == Global.event_place && DBReader.GetString(3) == Global.event_stu && DBReader.GetString(7) == "n") //依位置判斷未處理的異常事件 { tB_place.Text = DBReader.GetString(5); tB_temp.Text = DBReader.GetString(6); tB_date.Text = DBReader.GetString(1); tB_time.Text = DBReader.GetString(2); Time = DBReader.GetString(2); //抓學生資料 string stu_id = DBReader.GetString(3); MySQLCommand DBCom = new MySQLCommand("select * from `RFID_Project`.`student`", DBConn); MySQLDataReader DBReader_stu = DBCom.ExecuteReaderEx(); DBReader_stu.Read(); do { if (DBReader_stu.GetString(0) == stu_id) { tB_id.Text = DBReader_stu.GetString(0); tB_name.Text = DBReader_stu.GetString(2); tB_sex.Text = DBReader_stu.GetString(5); tB_tagId.Text = DBReader_stu.GetString(1); tB_class.Text = DBReader_stu.GetString(6); tB_CWHO.Text = DBReader_stu.GetString(8); tB_CTEL.Text = DBReader_stu.GetString(9); tB_address.Text = DBReader_stu.GetString(7); pB_photo.ImageLocation = DBReader_stu.GetString(4); //圖片 //抓老師資料 MySQLCommand DBComT = new MySQLCommand("select * from `RFID_Project`.`teacher`", DBConn); MySQLDataReader DBReader_teacher = DBComT.ExecuteReaderEx(); DBReader_teacher.Read(); do { if (DBReader_teacher.GetString(2) == DBReader_stu.GetString(6)) { tB_teacher.Text = DBReader_teacher.GetString(1); tB_tTEL.Text = DBReader_teacher.GetString(4); } } while (DBReader_teacher.Read()); } } while (DBReader_stu.Read()); break; } } }
public Dictionary <string, object> selectArticleByCollect(int id) { init(); con.Open(); string sql = "select b.* from collect_list a RIGHT JOIN article b on b.id = a.article_id " + "where a.user_id = " + id; System.Diagnostics.Debug.WriteLine(sql); MySQLCommand cmd = new MySQLCommand(sql, con); MySQLDataReader reader = cmd.ExecuteReaderEx(); List <Article> articles = new List <Article>(); while (reader.Read()) { byte[] buf0 = (byte[])reader[1]; byte[] buf1 = (byte[])reader[3]; byte[] buf2 = (byte[])reader[4]; byte[] buf3 = (byte[])reader[5]; articles.Add(new Article((int)reader[0], encode.numToString(System.Text.Encoding.UTF8.GetString(buf0)), (int)reader[2], encode.numToString(System.Text.Encoding.UTF8.GetString(buf1)), encode.numToString(System.Text.Encoding.UTF8.GetString(buf2)), encode.numToString(System.Text.Encoding.UTF8.GetString(buf3)), (string)reader[6], (string)reader[7], (string)reader[8], (int)reader[9], (int)reader[10], (int)reader[11], (int)reader[12], (int)reader[13], reader[14].ToString())); } List <string> usernames = new List <string>(); foreach (Article article in articles) { sql = "select name from user where id = " + article.userId; cmd = new MySQLCommand(sql, con); reader = cmd.ExecuteReaderEx(); while (reader.Read()) { usernames.Add((string)reader[0]); } } Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("articles", articles); dic.Add("usernames", usernames); return(dic); }
public PasteCode selectPasteCodeById(int id) { init(); con.Open(); string sql = "select * from paste_code where " + "id = " + id; System.Diagnostics.Debug.WriteLine(sql); MySQLCommand cmd = new MySQLCommand(sql, con); MySQLDataReader reader = cmd.ExecuteReaderEx(); PasteCode pasteCode = new PasteCode(); while (reader.Read()) { pasteCode.id = (int)reader[0]; pasteCode.poster = reader[1].ToString(); System.Diagnostics.Debug.WriteLine(pasteCode.poster); pasteCode.language = reader[2].ToString(); System.Diagnostics.Debug.WriteLine(pasteCode.language); pasteCode.languagemode = reader[3].ToString(); System.Diagnostics.Debug.WriteLine(pasteCode.languagemode); pasteCode.theme = reader[4].ToString(); System.Diagnostics.Debug.WriteLine(pasteCode.theme); byte[] buf = (byte[])reader[5]; pasteCode.code = System.Text.Encoding.UTF8.GetString(buf); System.Diagnostics.Debug.WriteLine(pasteCode.code); pasteCode.time = reader[6].ToString(); System.Diagnostics.Debug.WriteLine(pasteCode.time); } con.Close(); return(pasteCode); }
public bool IsBangHuiNameExist(string strBhName) { MySQLConnection conn = this._DBConns.PopDBConnection(); bool result; try { string sql = string.Format("SELECT * FROM t_banghui where bhname='{0}'", strBhName); MySQLCommand cmd = new MySQLCommand(sql, conn); MySQLDataReader reader = cmd.ExecuteReaderEx(); if (reader.Read()) { result = true; } else { result = false; } } catch (Exception ex) { result = true; } finally { this._DBConns.PushDBConnection(conn); } return(result); }
public Dictionary <string, object> selectCommentByArticleId(int id) { init(); con.Open(); string sql = "select a.*,b.name from comment_list a right join user b on a.user_id = b.id " + "where a.article_id = " + id; System.Diagnostics.Debug.WriteLine(sql); MySQLCommand cmd = new MySQLCommand(sql, con); MySQLDataReader reader = cmd.ExecuteReaderEx(); List <Comment> comments = new List <Comment>(); List <string> usernames = new List <string>(); while (reader.Read()) { comments.Add(new Comment((int)reader[0], (int)reader[1], (int)reader[2], encode.numToString(System.Text.Encoding.UTF8.GetString((byte[])reader[3])), reader[4].ToString())); usernames.Add((string)reader[5]); } Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("comments", comments); dic.Add("usernames", usernames); con.Close(); return(dic); }
private JieriRecvKingItemData QueryRoleJieriRecvKing(DBManager dbMgr, string fromDate, string toDate, int roleID) { JieriRecvKingItemData result = null; MySQLConnection conn = null; try { conn = dbMgr.DBConns.PopDBConnection(); string cmdText = "SELECT t_roles.rid, t_roles.rname, t_roles.zoneid, x.totalrecv from t_roles, (SELECT t_jierizengsong.receiver, SUM(t_jierizengsong.goodscnt) AS totalrecv " + string.Format(" FROM t_jierizengsong WHERE t_jierizengsong.receiver={0} AND sendtime>= '{1}' AND sendtime<='{2}') x ", roleID, fromDate, toDate) + " where t_roles.isdel=0 and t_roles.rid = x.receiver "; MySQLCommand cmd = new MySQLCommand(cmdText, conn); MySQLDataReader reader = cmd.ExecuteReaderEx(); if (reader.Read()) { result = new JieriRecvKingItemData(); result.RoleID = Convert.ToInt32(reader["rid"].ToString()); result.Rolename = reader["rname"].ToString(); result.ZoneID = Convert.ToInt32(reader["zoneid"].ToString()); result.TotalRecv = Convert.ToInt32(reader["totalrecv"].ToString()); result.Rank = -1; } GameDBManager.SystemServerSQLEvents.AddEvent(string.Format("+SQL: {0}", cmdText), EventLevels.Important); cmd.Dispose(); } finally { if (null != conn) { dbMgr.DBConns.PushDBConnection(conn); } } return(result); }
public void Grview(string str) { try { MySQLConnection DBConn; DBConn = new MySQLConnection(new MySQLConnectionString(Form2.Ip, Form2.KuName, Form2.Username, Form2.Password, Form2.Port).AsString); DBConn.Open(); //清空数据 dataGridView1.Rows.Clear(); int i = 0; MySQLCommand DBComm = new MySQLCommand("select id,DATE,IP,URL,CLASS,MD5 from xls where CLASS='" + str + "'", DBConn); MySQLDataReader DBReader = DBComm.ExecuteReaderEx(); while (DBReader.Read()) { i = dataGridView1.Rows.Add(); dataGridView1.Rows[i].Cells[0].Value = DBReader.GetString(0); dataGridView1.Rows[i].Cells[1].Value = DBReader.GetString(1); dataGridView1.Rows[i].Cells[2].Value = DBReader.GetString(2); dataGridView1.Rows[i].Cells[3].Value = DBReader.GetString(3); dataGridView1.Rows[i].Cells[4].Value = DBReader.GetString(4); dataGridView1.Rows[i].Cells[5].Value = DBReader.GetString(5); } DBConn.Close(); } finally { } }
public static List <string> Query() { List <string> ret = new List <string>(); lock (conn) { try { MySQLCommand commn; commn = new MySQLCommand("create table if not exists monsqldb (text varchar(1000))", conn); commn.ExecuteNonQuery(); commn = new MySQLCommand("select text from monsqldb", conn); MySQLDataReader mdr = commn.ExecuteReaderEx(); while (mdr.Read()) { ret.Add(mdr.GetString(0)); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("数据库访问出错:" + ex.Message); } } return(ret); }
private RoleCustomData QueryRoleCustomData(int roleId) { RoleCustomData roleCustomData = null; using (MyDbConnection3 conn = new MyDbConnection3(false)) { try { string cmdText = string.Format("select `occu_data`,`roledata4selector` from t_roledata where rid={0}", roleId); MySQLDataReader reader = conn.ExecuteReader(cmdText, new MySQLParameter[0]); if (reader.Read()) { byte[] bytes0 = reader[0] as byte[]; byte[] bytes = reader[1] as byte[]; roleCustomData = new RoleCustomData(); roleCustomData.roleId = roleId; if (null != bytes0) { roleCustomData.customDataList = DataHelper.BytesToObject <List <RoleCustomDataItem> >(bytes0, 0, bytes0.Length); } if (null != bytes) { roleCustomData.roleData4Selector = DataHelper.BytesToObject <RoleData4Selector>(bytes, 0, bytes.Length); } } } catch (Exception ex) { LogManager.WriteException(ex.ToString()); } } return(roleCustomData); }
public User selectUserById(int id) { init(); con.Open(); string sql = "select * from user where " + "id = " + id; System.Diagnostics.Debug.WriteLine(sql); MySQLCommand cmd = new MySQLCommand(sql, con); MySQLDataReader reader = cmd.ExecuteReaderEx(); User user = new User(); if (!reader.Read()) { return(null); } else { user.id = (int)reader[0]; user.name = (string)reader[1]; user.password = (string)reader[2]; user.phone = (string)reader[3]; user.email = (string)reader[4]; user.registerTime = reader[5].ToString(); user.isAdmin = (int)reader[6]; user.follow = (int)reader[7]; user.fans = (int)reader[8]; user.like = (int)reader[9]; user.collect = (int)reader[10]; user.comment = (int)reader[11]; } con.Close(); return(user); }
public void SelectBlob(MySQLConnection con) { try { con.Open(); MySQLCommand cmd = new MySQLCommand("select col1, col2 from `trntipos` where col1=3", con); //, `SerialNumberLastUsed` cmd.UsePreparedStatement = true; cmd.ServerCursor = true; cmd.Prepare(); MySQLDataReader reader = (MySQLDataReader)cmd.ExecuteReader(); while (reader.Read()) { getBLOBFile("output.jpg", reader, 1); } reader.Close(); cmd.Dispose(); con.Close(); } catch (Exception e) { if (con != null) { con.Close(); } throw e; } }
public string ToClass(string str) { string flag = ""; MySQLConnection DBConn; DBConn = new MySQLConnection(new MySQLConnectionString(Form2.Ip, Form2.KuName, Form2.Username, Form2.Password, Form2.Port).AsString); DBConn.Open(); MySQLCommand DBComm = new MySQLCommand("select CLASS from config", DBConn); MySQLDataReader DBReader = DBComm.ExecuteReaderEx(); while (DBReader.Read()) { flag = DBReader.GetString(0); DBComm = new MySQLCommand("select keyword from config where CLASS='" + DBReader.GetString(0) + "'", DBConn); MySQLDataReader DBReader1 = DBComm.ExecuteReaderEx(); if (DBReader1.Read()) { if (str.Contains(DBReader1.GetString(0))) { flag = DBReader.GetString(0); DBConn.Close(); return(flag); } } } DBConn.Close(); return(flag); }
/*public int ConMysql() * { * MySQLConnection DBConn; * DBConn = new MySQLConnection(new MySQLConnectionString(Form2.Ip, Form2.KuName, Form2.Username, Form2.Password, Form2.Port).AsString); * DBConn.Open(); * return 0; * } * * public int CloseMysql(MySQLConnection DBConn) * { * DBConn.Close(); * return 0; * }*/ public static int Joinclass() { if (Form3.key != "") { MySQLConnection DBConn; DBConn = new MySQLConnection(new MySQLConnectionString(Form2.Ip, Form2.KuName, Form2.Username, Form2.Password, Form2.Port).AsString); DBConn.Open(); MySQLCommand DBComm = new MySQLCommand("select CLASS from config where CLASS='" + Form3.cla + "'", DBConn); MySQLDataReader DBReader = DBComm.ExecuteReaderEx(); if (!DBReader.Read()) { DBComm = new MySQLCommand("insert into config(CLASS) values('" + Form3.cla + "')", DBConn); DBComm.ExecuteNonQuery(); } else if (Form3.cla != DBReader.GetString(0)) { DBComm = new MySQLCommand("insert into config(CLASS) values('" + Form3.cla + "')", DBConn); DBComm.ExecuteNonQuery(); } DBComm = new MySQLCommand("update config set keyword='" + Form3.key + "' where CLASS='" + Form3.cla + "'", DBConn); DBComm.ExecuteNonQuery(); DBConn.Close(); } return(0); }
private void button1_Click(object sender, EventArgs e) { string search = textBox1.Text; try { MySQLConnection DBConn; DBConn = new MySQLConnection(new MySQLConnectionString(Form2.Ip, Form2.KuName, Form2.Username, Form2.Password, Form2.Port).AsString); DBConn.Open(); //清空数据 dataGridView1.Rows.Clear(); int i = 0; MySQLCommand DBComm = new MySQLCommand("select id,DATE,IP,URL,CLASS,MD5 from xls where URL like '%" + search + "%'", DBConn); MySQLDataReader DBReader = DBComm.ExecuteReaderEx(); while (DBReader.Read()) { i = dataGridView1.Rows.Add(); dataGridView1.Rows[i].Cells[0].Value = DBReader.GetString(0); dataGridView1.Rows[i].Cells[1].Value = DBReader.GetString(1); dataGridView1.Rows[i].Cells[2].Value = DBReader.GetString(2); dataGridView1.Rows[i].Cells[3].Value = DBReader.GetString(3); dataGridView1.Rows[i].Cells[4].Value = DBReader.GetString(4); dataGridView1.Rows[i].Cells[5].Value = DBReader.GetString(5); } DBConn.Close(); } catch (MySQLException) { MessageBox.Show("请先连接数据库!"); } }
private void ButtonMagInfo_Click(object sender, EventArgs e) { MySQLConnection SQLconnection = new MySQLConnection(new MySQLConnectionString ("localhost", "DormitoryManage", "root", "123456").AsString); string SQLstr = "SELECT * FROM manager_info WHERE managerNumber = " + PublicValue.MAGNUM; SQLconnection.Open(); MySQLCommand SQLcommand1 = new MySQLCommand("SET NAMES GB2312", SQLconnection); SQLcommand1.ExecuteNonQuery(); //执行设置字符集的语句 MySQLCommand SQLcommand2 = new MySQLCommand(SQLstr, SQLconnection); MySQLDataReader SQLreader = (MySQLDataReader)SQLcommand2.ExecuteReader(); if (SQLreader.Read()) { this.TextBox1.Text = SQLreader["managerNumber"].ToString(); this.TextBox2.Text = SQLreader["managerName"].ToString(); this.TextBox3.Text = SQLreader["managerGender"].ToString(); this.TextBox4.Text = SQLreader["managerAge"].ToString(); this.TextBox5.Text = SQLreader["dormitoryNumber"].ToString(); this.TextBox6.Text = SQLreader["managerPosition"].ToString(); this.TextBox7.Text = SQLreader["managerPhone"].ToString(); this.TextBox8.Text = SQLreader["managerPassword"].ToString(); } SQLconnection.Close(); }
/// <summary> /// Gets the volunteer timestamps to an array.@deprecated Use getLastActiveTimestamp. unstable!! /// </summary> /// <param name="VolunteerID"></param> /// <param name="ACTIVE_ONLY"></param> /// <param name="ONLY_TODAY"></param> /// <returns>A 2 dimension array of timestamps or an empty array</returns> public object [][] getVolunteerTimestamps(uint VolunteerID,Boolean ACTIVE_ONLY=false,Boolean ONLY_TODAY=true){ //Build Query string qry="SELECT * FROM Checkin WHERE VolunteerID="+VolunteerID; if(ACTIVE_ONLY==true) qry+=" AND Active=1"; if(ONLY_TODAY==true) qry+=" AND DATE(TimeIn)=DATE(NOW())"; qry+=" ORDER BY CheckID DESC;"; //Query Data MySQLCommand mc = new MySQLCommand(qry, vlcon); MySQLDataReader dr = mc.ExecuteReaderEx(); List<object>[] rval = { new List<object>(), new List<object>(), new List<object>(), new List<object>()};//data string list int cnt=0; try{ while (dr.Read()) { for (byte curfield = 0; curfield < rval.Length; curfield++) { rval[curfield].Insert(cnt, dr.GetString(curfield)); Console.WriteLine(rval.GetValue(curfield).ToString()); } cnt++; } }finally{ dr.Close(); mc.Dispose(); } return new object[][]{rval[0].ToArray(),rval[1].ToArray(),rval[2].ToArray(),rval[3].ToArray()}; }
public static void SelectBoCaiShop(string Periods, out List <BoCaiShopDB> dList) { dList = null; try { using (MyDbConnection3 conn = new MyDbConnection3(false)) { string sql = string.Format("SELECT rid, ID, BuyNum, WuPinID from t_bocai_shop where Periods={0}", Periods); MySQLDataReader reader = conn.ExecuteReader(sql, new MySQLParameter[0]); dList = new List <BoCaiShopDB>(); while (reader.Read()) { BoCaiShopDB temp = new BoCaiShopDB(); temp.RoleID = Convert.ToInt32(reader["rid"].ToString()); temp.ID = Convert.ToInt32(reader["ID"].ToString()); temp.BuyNum = Convert.ToInt32(reader["BuyNum"].ToString()); temp.WuPinID = reader["WuPinID"].ToString(); temp.Periods = Convert.ToInt32(Periods); dList.Add(temp); } } } catch (Exception ex) { LogManager.WriteLog(LogTypes.Exception, string.Format("[ljl]{0}", ex.ToString()), null, true); } }
private void GetJieRiHongBaoRankList(GameServerClient client, int nID, byte[] cmdParams, int count) { List <JieriHongBaoKingItemData> list = new List <JieriHongBaoKingItemData>(); try { List <string> args = DataHelper.BytesToObject <List <string> >(cmdParams, 0, count); using (MyDbConnection3 conn = new MyDbConnection3(false)) { string cmdText = string.Format("SELECT `rid`,`count`,`getawardtimes`,`lasttime`,`rname` FROM `t_hongbao_jieri_recv` WHERE `keystr`='{0}' ORDER BY `count` DESC,`lasttime` ASC,rid ASC limit {1};", args[0], args[1]); using (MySQLDataReader reader = conn.ExecuteReader(cmdText, new MySQLParameter[0])) { int ranking = 1; while (reader.Read()) { list.Add(new JieriHongBaoKingItemData { RoleID = Global.SafeConvertToInt32(reader[0].ToString(), 10), TotalRecv = Global.SafeConvertToInt32(reader[1].ToString(), 10), GetAwardTimes = Global.SafeConvertToInt32(reader[2].ToString(), 10), Rolename = reader[4].ToString(), Rank = ranking++ }); } } } } catch (Exception ex) { LogManager.WriteException(ex.ToString()); } client.sendCmd <List <JieriHongBaoKingItemData> >(nID, list); }
public int insertNewPasteCode(PasteCode pasteCode) { init(); con.Open(); string sql = "insert into paste_code value(null," + "\"" + pasteCode.poster + "\"," + "\"" + pasteCode.language + "\"," + "\"" + pasteCode.languagemode + "\"," + "\"" + pasteCode.theme + "\"," + "\"" + pasteCode.code + "\"," + "\"" + pasteCode.time + "\")"; System.Diagnostics.Debug.WriteLine(sql); MySQLCommand cmd = new MySQLCommand(sql, con); cmd.ExecuteNonQuery(); sql = "select id from paste_code where " + "poster = " + "\"" + pasteCode.poster + "\" && " + "time = " + "\"" + pasteCode.time + "\""; System.Diagnostics.Debug.WriteLine(sql); cmd = new MySQLCommand(sql, con); MySQLDataReader reader = cmd.ExecuteReaderEx(); int id = 0; while (reader.Read()) { id = (int)reader[0]; } con.Close(); return(id); }
//显示数据按钮 private void button4_Click_1(object sender, EventArgs e) { MySQLConnection myconn = null; myconn = new MySQLConnection(new MySQLConnectionString("localhost", "water", "root", "root", 3306).AsString); try { myconn.Open(); //打开连接 MySQLCommand cmd = new MySQLCommand("select * from waterinfor", myconn); //cmd.ExecuteNonQuery(); MySQLDataReader sdr = cmd.ExecuteReaderEx(); while (sdr.Read()) { //构建一个ListView的数据,存入数据库数据,以便添加到listView1的行数据中 ListViewItem lt = new ListViewItem(); //将数据库数据转变成ListView类型的一行数据 lt.Text = sdr["id"].ToString(); lt.SubItems.Add(sdr["time"].ToString()); lt.SubItems.Add(sdr["place"].ToString()); // lt.SubItems.Add(sdr.GetString ( 2 )); lt.SubItems.Add(sdr["value"].ToString()); // Console.WriteLine(st); // Console.WriteLine(System.Text.Encoding.Default.EncodingName); //将lt数据添加到listView1控件中 listView1.Items.Add(lt); } myconn.Close(); sdr.Close(); } catch { myconn.Close(); } }
private List <AllyLogData> GetAllyLogData(int unionID) { List <AllyLogData> result; lock (this._lock) { List <AllyLogData> list = new List <AllyLogData>(); using (MyDbConnection3 conn = new MyDbConnection3(false)) { string cmdText = string.Format("SELECT unionID,unionZoneID,unionName,logTime,logState FROM t_ally_log WHERE myUnionID={0} ORDER BY logTime DESC LIMIT 20", unionID); MySQLDataReader reader = conn.ExecuteReader(cmdText, new MySQLParameter[0]); while (reader.Read()) { list.Add(new AllyLogData { MyUnionID = unionID, UnionID = int.Parse(reader["unionID"].ToString()), UnionZoneID = int.Parse(reader["unionZoneID"].ToString()), UnionName = reader["unionName"].ToString(), LogTime = DateTime.Parse(reader["logTime"].ToString()), LogState = int.Parse(reader["logState"].ToString()) }); } } result = list; } return(result); }
public static string GetAward(DBManager dbMgr, int zoneID, int roleID) { string result = ""; MySQLConnection conn = null; try { conn = dbMgr.DBConns.PopDBConnection(); string cmdText = string.Format("SELECT type,state FROM t_spread_award WHERE zoneID = '{0}' AND roleID = '{1}'", zoneID, roleID); MySQLCommand cmd = new MySQLCommand(cmdText, conn); MySQLDataReader reader = cmd.ExecuteReaderEx(); while (reader.Read()) { if (result != "") { result += "$"; } result = result + reader["type"].ToString() + "#"; result += reader["state"].ToString(); } GameDBManager.SystemServerSQLEvents.AddEvent(string.Format("+SQL: {0}", cmdText), EventLevels.Important); cmd.Dispose(); } finally { if (null != conn) { dbMgr.DBConns.PushDBConnection(conn); } } return(result); }
private void ButtonCheckIn_Click(object sender, EventArgs e) { MySQLConnection SQLconnection = new MySQLConnection(new MySQLConnectionString ("localhost", "DormitoryManage", "root", "123456").AsString); string SQLstr = "SELECT checkInTime,isChangeRoom FROM check_in WHERE studentNumber = " + PublicValue.STUNUM; SQLconnection.Open(); MySQLCommand SQLcommand1 = new MySQLCommand("SET NAMES GB2312", SQLconnection); SQLcommand1.ExecuteNonQuery(); //执行设置字符集的语句 MySQLCommand SQLcommand2 = new MySQLCommand(SQLstr, SQLconnection); MySQLDataReader SQLreader = (MySQLDataReader)SQLcommand2.ExecuteReader(); if (SQLreader.Read()) { string tempa = SQLreader["checkInTime"].ToString(); string tempb = SQLreader["isChangeRoom"].ToString(); if (tempb == "是") { MessageBox.Show(" 入住时间:" + tempa + "\n 有换过寝室", "入住信息"); } if (tempb == "否") { MessageBox.Show(" 入住时间:" + tempa + "\n 没有换过寝室", "入住信息"); } } SQLconnection.Close(); }
static void Main(string[] args) { conn = new MySQLConnection(new MySQLConnectionString("10.125.103.139", "heartlink", "qwe", "123").AsString); cmd = new MySQLCommand(); da = new MySQLDataAdapter(); String pass = "******"; String sql = "select ID from students where password="******"ID = {0}", DBReader.GetString(0)); } } finally { DBReader.Close(); conn.Close(); } }
public List <ReturnData> ReturnList() { List <ReturnData> list = new List <ReturnData>(); using (MyDbConnection3 conn = new MyDbConnection3(false)) { string cmdText = string.Format("SELECT id,activityID,activityDay,pzoneID,proleID,czoneID,croleID,vip,`level`,logTime,checkState,logState FROM t_user_return order by logTime", new object[0]); MySQLDataReader reader = conn.ExecuteReader(cmdText, new MySQLParameter[0]); while (reader.Read()) { list.Add(new ReturnData { DBID = Convert.ToInt32(reader["id"].ToString()), ActivityID = Convert.ToInt32(reader["activityID"].ToString()), ActivityDay = reader["activityDay"].ToString(), PZoneID = Convert.ToInt32(reader["pzoneID"].ToString()), PRoleID = Convert.ToInt32(reader["proleID"].ToString()), CZoneID = Convert.ToInt32(reader["czoneID"].ToString()), CRoleID = Convert.ToInt32(reader["croleID"].ToString()), Vip = Convert.ToInt32(reader["vip"].ToString()), Level = Convert.ToInt32(reader["level"].ToString()), LogTime = Convert.ToDateTime(reader["logTime"].ToString()), StateCheck = Convert.ToInt32(reader["checkState"].ToString()), StateLog = Convert.ToInt32(reader["logState"].ToString()) }); } } return(list); }
public ReturnData GetUserReturnData(string userID, int zoneID) { ReturnData result = null; using (MyDbConnection3 conn = new MyDbConnection3(false)) { string cmdText = string.Format("select vip,level,checkState,logTime from t_user_return where userid='{0}' and zoneID='{1}' and activityDay='{2}' and activityID='{3}'", new object[] { userID, zoneID, UserReturnManager._activityInfo.ActivityDay, UserReturnManager._activityInfo.ActivityID }); MySQLDataReader reader = conn.ExecuteReader(cmdText, new MySQLParameter[0]); if (reader.Read()) { int inputMoneyInPeriod = DBQuery.GetUserInputMoney(TCPManager.getInstance().DBMgr, userID, 0, UserReturnManager._activityInfo.ActivityDay, "2050-01-01 00:00:00"); if (inputMoneyInPeriod < 0) { inputMoneyInPeriod = 0; } int roleYuanBaoInPeriod = Global.TransMoneyToYuanBao(inputMoneyInPeriod); result = new ReturnData { Vip = Convert.ToInt32(reader["vip"].ToString()), Level = Convert.ToInt32(reader["level"].ToString()), StateCheck = Convert.ToInt32(reader["checkState"].ToString()), LogTime = DateTime.Parse(reader["logTime"].ToString()), LeiJiChongZhi = roleYuanBaoInPeriod }; } } return(result); }
private void timer5_Tick(object sender, EventArgs e) { DBConn.Open(); MySQLCommand DBComm = new MySQLCommand("select * from `parkingsystem`.`record`", DBConn); MySQLCommand firstCmd = new MySQLCommand("set names big5", DBConn); firstCmd.ExecuteNonQuery(); MySQLDataReader DBReader = DBComm.ExecuteReaderEx(); bool s = true; while (DBReader.Read()) { if (DBReader.GetString(2) == "E" || DBReader.GetString(2) == "") { tSSL_C.Text = "開啟"; s = false; break; } } if (s) { tSSL_C.Text = "關閉"; } DBConn.Close(); }
private void Read(ref List<string[]> result) { oraRD = cmd.ExecuteReaderEx(); int n = oraRD.FieldCount; while (oraRD.Read()) { string[] oneResult = new string[n]; for (int i = 0; i < n; i++) { oneResult[i] = oraRD[i].ToString(); } result.Add(oneResult); } oraRD.Close(); }