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 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); }
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(); } }
public void InsertBlob(MySQLConnection con) { try { con.Open(); MySQLCommand cmd = new MySQLCommand("INSERT INTO `trntipos`(col1, col2) values (?, ?)", con); //, `SerialNumberLastUsed` MySQLParameter p1 = new MySQLParameter("@col1", DbType.Int32); MySQLParameter p2 = new MySQLParameter("@col2", DbType.Binary); p2.Value = GetBinary(@"myblob.jpg"); p1.Value = 1; cmd.UsePreparedStatement = true; cmd.Parameters.Add(p1); cmd.Parameters.Add(p2); cmd.Prepare(); int affectedrows = cmd.ExecuteNonQuery(); cmd.Dispose(); con.Close(); } catch (Exception e) { if (con != null) { con.Close(); } throw e; } }
public int TestSelect(MySQLConnection con, bool useNew) { int affectedrows = 0; try { con.Open(); MySQLCommand cmd = new MySQLCommand("SELECT col1, col2, col3, col4 FROM `test_table`", con); if (useNew) { cmd.UsePreparedStatement = true; cmd.ServerCursor = true; cmd.Prepare(); } IDataReader reader = cmd.ExecuteReader(); MySQLCommand cmd1 = new MySQLCommand("SELECT col1, col2, col3, col4 FROM `test_table`", con); if (useNew) { cmd1.UsePreparedStatement = true; //cmd.ServerCursor = true; cmd.FetchSize = 10; cmd1.Prepare(); } while (reader.Read()) { affectedrows++; IDataReader reader1 = cmd1.ExecuteReader(); while (reader1.Read()) { affectedrows++; long s1 = reader1.GetInt64(0); string st1 = reader1.GetString(1); DateTime dt1 = reader1.GetDateTime(3); } reader1.Close(); long s = reader.GetInt64(0); string st = reader.GetString(1); DateTime dt = reader.GetDateTime(3); } reader.Close(); cmd.Dispose(); con.Close(); return(affectedrows); } catch (Exception e) { if (con != null) { con.Close(); } throw e; } }
public int InsertTest(MySQLConnection con, bool useNew) { try { con.Open(); MySQLCommand cmd; if (useNew) { cmd = new MySQLCommand("INSERT INTO `test_table` (col1, col2, col3, col4) values (?,?,?,?)", con); //, `SerialNumberLastUsed` cmd.UsePreparedStatement = true; cmd.ServerCursor = false; cmd.Prepare(); } else { cmd = new MySQLCommand("INSERT INTO `test_table`(col1, col2, col3, col4) values (@col1, @col2, @col3, @col4)", con); //, `SerialNumberLastUsed` } MySQLParameter p1 = new MySQLParameter("@col1", DbType.Int32); cmd.Parameters.Add(p1); MySQLParameter p2 = new MySQLParameter("@col2", DbType.String); cmd.Parameters.Add(p2); MySQLParameter p3 = new MySQLParameter("@col1", DbType.Int16); cmd.Parameters.Add(p3); MySQLParameter p4 = new MySQLParameter("@col4", DbType.DateTime); cmd.Parameters.Add(p4); int affectedrows = 0; for (int i = 0; i < count; i++) { p4.Value = DateTime.Now; p1.Value = i; p2.Value = "Registro número " + i; p2.Size = p2.Value.ToString().Length; p3.Value = i * 10; affectedrows += cmd.ExecuteNonQuery(); } cmd.Dispose(); con.Close(); return(affectedrows); } catch (Exception e) { if (con != null) { con.Close(); } throw e; } }
private void User_Load(object sender, EventArgs e) { conn1.Open(); string sql = "select mealcardid as '饭卡ID号',mealcardinformation as '饭卡余额', mealcardstatus as '饭卡状态' from mealcard"; MySQLDataAdapter ada1 = new MySQLDataAdapter(sql, conn1); DataSet ds1 = new DataSet(); ada1.Fill(ds1); dataGridView1.DataSource = ds1.Tables[0]; sql = "select dishid as '菜品ID号', dishquantity as '菜品数量', dishinformation as '菜品单价',dishstatus as '菜品状态' from Dish"; MySQLDataAdapter ada2 = new MySQLDataAdapter(sql, conn1); DataSet ds2 = new DataSet(); ada2.Fill(ds2); dataGridView2.DataSource = ds2.Tables[0]; conn1.Close(); this.timer1.Start(); switch (DateTime.Now.DayOfWeek.ToString()) { case "Monday": weekstr = "星期一"; break; case "Tuesday": weekstr = "星期二"; break; case "Wednesday": weekstr = "星期三"; break; case "Thursday": weekstr = "星期四"; break; case "Friday": weekstr = "星期五"; break; case "Saturday": weekstr = "星期六"; break; case "Sunday": weekstr = "星期日"; break; } }
/*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("请先连接数据库!"); } }
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 { } }
//获得数据库数据 private void GetUserData() { MySQLConnection DBConn = null; DBConn = new MySQLConnection(new MySQLConnectionString(Configuration.getDBIp(), "workflow", Configuration.getDBUsername(), Configuration.getDBPassword()).AsString); DBConn.Open(); MySQLCommand setformat = new MySQLCommand("set names gb2312", DBConn); setformat.ExecuteNonQuery(); setformat.Dispose(); string sql = "select distinct User_Dept from tb_user"; MySQLDataAdapter mda = new MySQLDataAdapter(sql, DBConn); DataTable ds = new DataTable(); mda.Fill(ds); DBConn.Close(); foreach (DataRow dr in ds.Rows) { UserModel um = new UserModel(); um.Department = dr["User_Dept"].ToString(); models.Add(um); } view.Source = models; this.listView1.DataContext = view; }
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(); } }
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(); }
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(); }
//获得数据库数据 private void GetUserData() { MySQLConnection DBConn = null; DBConn = new MySQLConnection(new MySQLConnectionString(Configuration.getDBIp(), "template", Configuration.getDBUsername(), Configuration.getDBPassword()).AsString); DBConn.Open(); MySQLCommand setformat = new MySQLCommand("set names gb2312", DBConn); setformat.ExecuteNonQuery(); setformat.Dispose(); string type = MainWindow.wfmodel.WFModel_Type; string sql = "select name, description,type from template where type = '"+type+"'"; MySQLDataAdapter mda = new MySQLDataAdapter(sql, DBConn); DataTable ds = new DataTable(); mda.Fill(ds); DBConn.Close(); foreach (DataRow dr in ds.Rows) { TemplateModel um = new TemplateModel(); um.name = dr["name"].ToString(); um.desc = dr["description"].ToString(); um.type = dr["type"].ToString(); models.Add(um); } view.Source = models; this.listView1.DataContext = view; }
//获得数据库数据 private void GetUserData() { MySQLConnection DBConn = null; DBConn = new MySQLConnection(new MySQLConnectionString(Configuration.getDBIp(), "template", Configuration.getDBUsername(), Configuration.getDBPassword()).AsString); DBConn.Open(); MySQLCommand setformat = new MySQLCommand("set names gb2312", DBConn); setformat.ExecuteNonQuery(); setformat.Dispose(); string type = MainWindow.wfmodel.WFModel_Type; string sql = "select name, description,type from template where type = '" + type + "'"; MySQLDataAdapter mda = new MySQLDataAdapter(sql, DBConn); DataTable ds = new DataTable(); mda.Fill(ds); DBConn.Close(); foreach (DataRow dr in ds.Rows) { TemplateModel um = new TemplateModel(); um.name = dr["name"].ToString(); um.desc = dr["description"].ToString(); um.type = dr["type"].ToString(); models.Add(um); } view.Source = models; this.listView1.DataContext = view; }
public void closeConn() { if (this.conn != null) { conn.Close(); } }
public LateWtEl(string flag) { InitializeComponent(); string SQLstr = "\0"; MySQLConnection SQLconnection = new MySQLConnection(new MySQLConnectionString ("localhost", "DormitoryManage", "root", "123456").AsString); if (flag == "0") { this.Text = "晚归信息"; SQLstr = "SELECT studentNumber as '学号',lateReturnTime as '晚归时间' FROM late_return WHERE studentNumber = " + PublicValue.STUNUM; } else if (flag == "1") { this.Text = "水电信息"; SQLstr = "SELECT studentNumber as '学号', dormitoryNumber as '公寓号',roomNumber as '寝室号',checkMonth as '日期',electricityConsumption as '用电量',electricityBill as '电费',waterConsumption" + " as '用水量',waterBill as '水费' FROM Water_Electricity WHERE studentNumber = " + PublicValue.STUNUM; } SQLconnection.Open(); MySQLCommand SQLcommand = new MySQLCommand("SET NAMES GB2312", SQLconnection); SQLcommand.ExecuteNonQuery(); //执行设置字符集的语句 MySQLDataAdapter SQLadapter = new MySQLDataAdapter(SQLstr, SQLconnection); DataSet set = new DataSet(); SQLadapter.Fill(set); DataGridView.DataSource = set.Tables[0]; SQLconnection.Close(); }
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 GetUserData() { MySQLConnection DBConn = null; string connectStr = new MySQLConnectionString(Configuration.getDBIp(), "workflow", Configuration.getDBUsername(), Configuration.getDBPassword()).AsString; //System.Windows.Forms.MessageBox.Show(connectStr); DBConn = new MySQLConnection(connectStr); DBConn.Open(); MySQLCommand setformat = new MySQLCommand("set names gb2312", DBConn); setformat.ExecuteNonQuery(); setformat.Dispose(); string sql = "select User_Id,User_Name,User_Dept,User_Job,User_Mail,User_Cell from tb_user"; MySQLDataAdapter mda = new MySQLDataAdapter(sql, DBConn); DataTable ds = new DataTable(); mda.Fill(ds); DBConn.Close(); foreach (DataRow dr in ds.Rows) { UserModel um = new UserModel(); um.ID = dr["User_Id"].ToString(); um.Name = dr["User_Name"].ToString(); um.Department = dr["User_Dept"].ToString(); um.Email = dr["User_Mail"].ToString(); um.PersonPosition = dr["User_Job"].ToString(); um.Telephone = dr["User_Cell"].ToString(); models.Add(um); } view.Source = models; this.listView1.DataContext = view; }
public MyDbConnection1(string connStr, string dbNames) { bool success = false; MySQLConnection dbConn = null; try { Dictionary <string, string> mapParams = new Dictionary <string, string>(); string[] strParams = connStr.Split(';'); foreach (var param in strParams) { string[] map = param.Split('='); if (map.Length != 2) { continue; } map[0] = map[0].Trim(); map[1] = map[1].Trim(); mapParams[map[0]] = map[1]; } //Hashtable hashLog = (Hashtable)MUJson.jsonDecode("{" + connectionLogString + "}"); //Hashtable hashGame = (Hashtable)MUJson.jsonDecode("{" + connectionString + "}"); ConnStr = new MySQLConnectionString( mapParams["host"], mapParams["database"], mapParams["user id"], mapParams["password"] ); dbConn = new MySQLConnection(ConnStr.AsString); dbConn.Open(); //打开数据库连接 MySQLCommand cmd = null; //执行链接查询的字符集 if (!string.IsNullOrEmpty(dbNames)) { cmd = new MySQLCommand(string.Format("SET names '{0}'", dbNames), dbConn); cmd.ExecuteNonQuery(); } DatabaseName = DbConn.Database; success = true; DbConn = dbConn; } catch (Exception ex) { LogManager.WriteExceptionUseCache(ex.ToString()); } if (!success && null != dbConn) { try { dbConn.Close(); } catch { } } }
public void Test(MySQLConnection con) { try { con.Open(); MySQLCommand cmd = new MySQLCommand("SELECT col1, col2, col3, col4 FROM `test_table`", con); //, `SerialNumberLastUsed` cmd.UsePreparedStatement = true; cmd.ServerCursor = true; cmd.Prepare(); MySQLCommand cmd1 = new MySQLCommand("SELECT col1, col2 FROM `test_table`", con); //SerialNumberID IDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { IDataReader reader1 = cmd1.ExecuteReader(); while (reader1.Read()) { Console.Write(reader1.GetInt32(0) + " "); Console.WriteLine(reader1.GetString(1)); } reader1.Close(); Console.Write(reader.GetInt32(0) + " "); Console.WriteLine(reader.GetString(1)); Console.WriteLine(reader.GetDateTime(3)); Console.WriteLine(reader.IsDBNull(2)); Console.WriteLine(reader.GetInt16(2)); Console.WriteLine(reader.IsDBNull(0)); } reader.Close(); cmd1.Dispose(); cmd.Dispose(); con.Close(); } catch (Exception e) { if (con != null) { con.Close(); } throw e; } }
private void button1_Click(object sender, EventArgs e) { string choice; choice = comboBox1.Text; DBConn.Open(); MySQLCommand firstCmd = new MySQLCommand("set names big5", DBConn); firstCmd.ExecuteNonQuery(); MySQLCommand DBComm; MySQLDataReader DBReader; switch (choice) { case "車場硬體設備": DBComm = new MySQLCommand("select * from `parkingsystem`.`reader`", DBConn); DBReader = DBComm.ExecuteReaderEx(); Mshow.Text = (""); while (DBReader.Read()) { Mshow.Text += (" 編號: " + DBReader.GetValue(0)); Mshow.Text += (" 位置: " + DBReader.GetValue(1)); Mshow.Text += (" 購買日期: " + DBReader.GetValue(2)); Mshow.Text += (" 位置: " + DBReader.GetValue(3)); Mshow.Text += (" 購買價錢: " + DBReader.GetValue(4) + "\r\n"); } break; case "車輛停放記錄": DBComm = new MySQLCommand("select * from `parkingsystem`.`record`", DBConn); DBReader = DBComm.ExecuteReaderEx(); Mshow.Text = (""); while (DBReader.Read()) { Mshow.Text += (" 車號: " + DBReader.GetValue(1)); Mshow.Text += (" 進入日期: " + DBReader.GetValue(3)); Mshow.Text += (" 出去日期: " + DBReader.GetValue(4)); Mshow.Text += (" 消費經額: " + DBReader.GetValue(7) + "\r\n"); } break; case "管理人員資料": DBComm = new MySQLCommand("select * from `parkingsystem`.`manager`", DBConn); DBReader = DBComm.ExecuteReaderEx(); Mshow.Text = (""); while (DBReader.Read()) { Mshow.Text += (" 帳號: " + DBReader.GetValue(0)); Mshow.Text += (" 姓名: " + DBReader.GetValue(1)); Mshow.Text += (" 電話: " + DBReader.GetValue(4) + "\r\n"); } break; } DBConn.Close(); }
public static int OperateData(string sql) { using (MySQLConnection connection = new MySQLConnection(source())) { connection.Open(); DoSql(connection, sql); connection.Close(); } return(1); }
private void ButtonOK_Click(object sender, EventArgs e) { if (TextBox7.Text == "" || TextBox8.Text == "") { if (TextBox7.Text == "") { labelN1.Text = "输入不能未空"; } else { labelN1.Text = " "; } if (TextBox8.Text == "") { labelN2.Text = "输入不能未空"; } else { labelN2.Text = " "; } } else { labelN1.Text = " "; labelN2.Text = " "; int flag = 0; string tempa = TextBox7.Text; string tempb = TextBox8.Text; MySQLConnection SQLconnection = new MySQLConnection(new MySQLConnectionString ("localhost", "DormitoryManage", "root", "123456").AsString); string SQLstr1 = "SELECT * FROM manager_info WHERE managerNumber = " + PublicValue.MAGNUM; string SQLstr2 = "UPDATE manager_info set managerPhone = '" + TextBox7.Text + "',managerPassword = '******'"; SQLconnection.Open(); MySQLCommand SQLcommand1 = new MySQLCommand("SET NAMES GB2312", SQLconnection); SQLcommand1.ExecuteNonQuery(); //执行设置字符集的语句 MySQLCommand SQLcommand2 = new MySQLCommand(SQLstr1, SQLconnection); MySQLDataReader SQLreader = (MySQLDataReader)SQLcommand2.ExecuteReader(); if (SQLreader.Read()) { string oldtempa = SQLreader["managerPhone"].ToString(); string oldtempb = SQLreader["managerPassword"].ToString(); if (tempa != oldtempa || tempb != oldtempb) { flag = 1; } } if (flag == 1) { MySQLCommand SQLcommand3 = new MySQLCommand(SQLstr2, SQLconnection); SQLcommand3.ExecuteNonQuery(); SQLconnection.Close(); MessageBox.Show("修改成功", "提示"); } } }
//�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡι��캯�� public UserManager(string name) : base(name, 560, 300) { MySQLConnection obSql; string linkStr = new MySQLConnectionString("localhost", "flox", "root", "00", 3306).AsString; linkStr += ";Character Set=GBK"; obSql = new MySQLConnection(linkStr); obSql.Open(); // ִ�в�ѯ��� MessageBox.Show(linkStr, "���ӳɹ�"); MySQLCommand obCommand = null; MySQLDataReader obReader = null; string str = ""; try { obCommand = new MySQLCommand("select username from cdb_members", obSql); obReader = obCommand.ExecuteReaderEx(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "ִ�д���"); } if (obReader != null) { try { str += obReader.FieldCount.ToString() + "\r\n"; while (obReader.Read()) { for (int i = 0; i < obReader.FieldCount; i++) { string inputStr = obReader.GetString(i); #region //note ///Encoding inputCode = Encoding.GetEncoding("GBK"); ///Encoding outCode = Encoding.Unicode; ///byte[] bta = inputCode.GetBytes(inputStr); ///byte[] bta2 = Encoding.Convert(inputCode, outCode, bta); ///string outStr = outCode.GetString(bta2); #endregion str += inputStr; } str += "\r\n"; } } finally { obReader.Close(); obCommand.Dispose(); obSql.Close(); } } MessageBox.Show(str, "�û��б�"); }
public void Close() { if (null != DbConn) { try { DbConn.Close(); } catch { } } }
public void Delete(MySQLConnection con) { try { con.Open(); MySQLCommand cmd = new MySQLCommand("DELETE FROM `test_table`", con); //, `SerialNumberLastUsed` cmd.ExecuteNonQuery(); cmd.Dispose(); con.Close(); } catch (Exception e) { if (con != null) { con.Close(); } throw e; } }
//确认本次添加操作 private void Confirm_Click(object sender, RoutedEventArgs e) { //得到新的添加项 int id; DataRow row; row = TemplateSelectTable.NewRow(); DataRowView selectrow = ListBox2.SelectedItem as DataRowView; if (selectrow == null) { MessageBox.Show("请选择要添加的表单模板!"); return; } id = Convert.ToInt32(selectrow["ID"].ToString()); row["Template_Id"] = id; row["Template_Name"] = selectrow["NAME"].ToString(); foreach (DataRow dr in TemplateDataTable.Rows) { if (Convert.ToInt32(dr["ID"].ToString()) == id) { row["Template_HtmlSource"] = dr["HTMLSOURCE"].ToString(); row["Template_Description"] = dr["DESCRIPTION"].ToString(); break; } } TemplateSelectTable.Rows.Add(row); TemplateSelectTable.AcceptChanges(); //将添加的表单模板信息填入数据库的tb_templateselectlist表中 MySQLConnection DBConn = null; DBConn = new MySQLConnection(new MySQLConnectionString(Configuration.getDBIp(), "template", Configuration.getDBUsername(), Configuration.getDBPassword()).AsString); DBConn.Open(); AddFlag = false; for (int i = 0; i < TemplateSelectTable.Rows.Count; i++) { string sqlInsert = "insert into tb_templateselectlist(Template_Id , Template_Name,Template_HtmlSource,Template_Description) values ('" + TemplateSelectTable.Rows[i]["Template_Id"] + "' , '" + TemplateSelectTable.Rows[i]["Template_Name"] + "' , '" + TemplateSelectTable.Rows[i]["Template_HtmlSource"] + "' , '" + TemplateSelectTable.Rows[i]["Template_Description"] + "')"; MySQLCommand mySqlCommand = new MySQLCommand(sqlInsert, DBConn); try { mySqlCommand.ExecuteNonQuery(); AddFlag = true; } catch (Exception ex) { String message = ex.Message; MessageBox.Show("添加表单模板数据失败!该表单模板数据已存在于表中。" + message); } } DBConn.Close(); this.Close(); }
public void OpenAndClose() { using (var c = new MySQLConnection(ConnectionString)) { Assert.True(c.State == ConnectionState.Closed); c.Open(); Assert.True(c.State == ConnectionState.Open); c.Close(); Assert.True(c.State == ConnectionState.Closed); } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (conn != null && conn.State == ConnectionState.Open) { try { conn.Close(); } catch (Exception ex) { log(ex.Message); } } }
//获得数据库数据 void GetTemplateData() { models.Clear(); MySQLConnection DBConn = null; DBConn = new MySQLConnection(new MySQLConnectionString(Configuration.getDBIp(), "workflow", Configuration.getDBUsername(), Configuration.getDBPassword()).AsString); try { DBConn.Open(); MySQLCommand setformat = new MySQLCommand("set names gb2312", DBConn); setformat.ExecuteNonQuery(); setformat.Dispose(); string sql = "select model_name,owner,model_content,lastedit_time,model_disc,create_time from wf_model"; MySQLDataAdapter mda = new MySQLDataAdapter(sql, DBConn); DataTable ds = new DataTable(); mda.Fill(ds); DBConn.Close(); foreach (DataRow dr in ds.Rows) { WFModel wfm = new WFModel(); wfm.WFModel_CreateTime = dr["create_time"].ToString(); wfm.WFModel_LasteditTime = dr["lastedit_time"].ToString(); wfm.WFModel_Name = dr["model_name"].ToString(); wfm.WFModel_Owner = dr["owner"].ToString(); string test = dr["model_content"].ToString(); if (dr["model_content"] == null || dr["model_content"].ToString().Length<=0) { wfm.WFModel_Content = ""; }else wfm.WFModel_Content = Encoding.Default.GetString((Byte[])dr["model_content"]); models.Add(wfm); } view.Source = models; this.listView1.DataContext = view; } catch (Exception e) { MessageBox.Show("数据库连接失败,请检查网络连接或者数据库配置"); return; } }
//获得数据库数据 DataTable GeteData() { MySQLConnection DBConn = null; DBConn = new MySQLConnection(new MySQLConnectionString(Configuration.getDBIp(), "template", Configuration.getDBUsername(), Configuration.getDBPassword()).AsString); DBConn.Open(); //MySQLCommand DBCmd = new MySQLCommand("set names gb2312", DBConn); // DBCmd.ExecuteNonQuery(); string sql = "select * from template"; MySQLDataAdapter mda = new MySQLDataAdapter(sql, DBConn); DataTable ds = new DataTable(); mda.Fill(ds); DBConn.Close(); return ds; }
//执行SQL语句,返回影响的记录数 /// <summary> /// 执行SQL语句,返回影响的记录数 /// </summary> /// <param name="SQLString">SQL语句</param> /// <returns>影响的记录数</returns> public int ExecuteNonQuery(string SQLString) { using (MySQLConnection connection = new MySQLConnection(connectionString)) { using (MySQLCommand cmd = new MySQLCommand(SQLString, connection)) { try { connection.Open(); int rows = cmd.ExecuteNonQuery(); return rows; } catch (MySQLException e) { connection.Close(); throw e; } } } }
public static ToolboxCategoryItems loadTemplatebox() { MySQLConnection DBConn = new MySQLConnection(new MySQLConnectionString(Configuration.getDBIp(), "template", Configuration.getDBUsername(), Configuration.getDBPassword()).AsString); if (DBConn != null) { try { DBConn.Open(); string sql = "select * from template"; MySQLDataAdapter mda = new MySQLDataAdapter(sql, DBConn); MySQLCommand mcd = new MySQLCommand(sql, DBConn); mcd.ExecuteNonQuery(); DataTable TemplateDataTable = new DataTable(); mda.Fill(TemplateDataTable); DBConn.Close(); loadSystemIcon(); ToolboxCategoryItems toolboxCategoryItems = new ToolboxCategoryItems(); ToolboxCategory templates = new System.Activities.Presentation.Toolbox.ToolboxCategory("表单模板"); foreach (DataRow dr in TemplateDataTable.Rows) { ToolboxItemWrapper Template = new ToolboxItemWrapper(typeof(Wxwinter.BPM.WFDesigner.Template), dr["NAME"].ToString()); templates.Add(Template); } toolboxCategoryItems.Add(templates); parentWindow.statusInfo.Text = ""; return toolboxCategoryItems; } catch (Exception e) { parentWindow.statusInfo.Text = "数据库连接失败,请检查网络设置和数据库连接配置"; return null; } } else { return null; } }
public static DataTable ExecuteDataTable(string SQLString) { using (MySQLConnection connection = new MySQLConnection(connectionString)) { DataSet ds = new DataSet(); try { connection.Open(); MySQLDataAdapter command = new MySQLDataAdapter(SQLString, connection); MySQLCommand commn = new MySQLCommand("set names gbk", connection); commn.ExecuteNonQuery(); command.Fill(ds, "ds"); connection.Close(); } catch (MySQLException ex) { throw new Exception(ex.Message); } return ds.Tables[0]; } }
public void GetPeopleDate(string str) { models.Clear(); MySQLConnection DBConn = null; DBConn = new MySQLConnection(new MySQLConnectionString(Configuration.getDBIp(), "workflow", Configuration.getDBUsername(), Configuration.getDBPassword()).AsString); try { DBConn.Open(); MySQLCommand setformat = new MySQLCommand("set names gb2312", DBConn); setformat.ExecuteNonQuery(); setformat.Dispose(); string sql = "select tb_per.User_Name , tb_user.User_Mail from tb_user, tb_per where tb_per.user_name = tb_user.User_Name and tb_per.user_authority = "; sql += "'" + str + "'"; //MessageBox.Show(sql); MySQLDataAdapter mda = new MySQLDataAdapter(sql, DBConn); DataTable ds = new DataTable(); mda.Fill(ds); DBConn.Close(); foreach (DataRow dr in ds.Rows) { peopleInfo wfm = new peopleInfo(); wfm.peopleName = dr["user_name"].ToString(); wfm.peopleEmail = dr["User_Mail"].ToString(); models.Add(wfm); } view.Source = models; this.peopleListView.DataContext = view; } catch (System.Exception ex) { MessageBox.Show("数据库连接失败,请检查网络连接或者数据库配置"); return; } }
//确认本次添加操作 private void Confirm_Click(object sender, RoutedEventArgs e) { //得到新的添加项 int id; DataRow row; row = TemplateSelectTable.NewRow(); DataRowView selectrow = ListBox2.SelectedItem as DataRowView; if (selectrow == null) { MessageBox.Show("请选择要添加的表单模板!"); return; } id = Convert.ToInt32(selectrow["ID"].ToString()); row["Template_Id"] = id; row["Template_Name"] = selectrow["NAME"].ToString(); foreach (DataRow dr in TemplateDataTable.Rows) { if ( Convert.ToInt32(dr["ID"].ToString()) == id) { row["Template_HtmlSource"] = dr["HTMLSOURCE"].ToString(); row["Template_Description"] = dr["DESCRIPTION"].ToString(); break; } } TemplateSelectTable.Rows.Add(row); TemplateSelectTable.AcceptChanges(); //将添加的表单模板信息填入数据库的tb_templateselectlist表中 MySQLConnection DBConn = null; DBConn = new MySQLConnection(new MySQLConnectionString(Configuration.getDBIp(), "template", Configuration.getDBUsername(), Configuration.getDBPassword()).AsString); DBConn.Open(); AddFlag = false; for (int i = 0; i < TemplateSelectTable.Rows.Count; i++) { string sqlInsert = "insert into tb_templateselectlist(Template_Id , Template_Name,Template_HtmlSource,Template_Description) values ('" + TemplateSelectTable.Rows[i]["Template_Id"] + "' , '" + TemplateSelectTable.Rows[i]["Template_Name"] + "' , '" + TemplateSelectTable.Rows[i]["Template_HtmlSource"] + "' , '" + TemplateSelectTable.Rows[i]["Template_Description"] + "')"; MySQLCommand mySqlCommand = new MySQLCommand(sqlInsert, DBConn); try { mySqlCommand.ExecuteNonQuery(); AddFlag = true; } catch (Exception ex) { String message = ex.Message; MessageBox.Show("添加表单模板数据失败!该表单模板数据已存在于表中。" + message); } } DBConn.Close(); this.Close(); }
//获取起始页码和结束页码 public static DataTable ExecuteDataTable(string cmdText, int startResord, int maxRecord) { using (MySQLConnection connection = new MySQLConnection(connectionString)) { DataSet ds = new DataSet(); try { connection.Open(); MySQLDataAdapter command = new MySQLDataAdapter(cmdText, connection); command.Fill(ds, startResord, maxRecord, "ds"); connection.Close(); } catch (MySQLException ex) { throw new Exception(ex.Message); } return ds.Tables[0]; } }
// X:\jsc.svn\examples\java\hybrid\Test\TestJVMCLRAsync\TestJVMCLRAsync\Program.cs // can we send in the caller IButtonProxy ? // as long the interface is async, one way we could do it. // if it allows a continuation we would have // to reinit our state // this would be possible only if we encrypt and sign // our state // as we cannot trust the other device to not change our expected state static ApplicationWebService() { // X:\jsc.svn\examples\javascript\LINQ\test\auto\TestSelect\TestAppEngineOrderByThenGroupBy\ApplicationWebService.cs // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201409/20140908 // jsc should not try to do cctor on client side // X:\jsc.svn\examples\javascript\Test\TestWebServiceStaticConstructor\TestWebServiceStaticConstructor\ApplicationWebService.cs #region MySQLConnection // X:\jsc.svn\examples\javascript\LINQ\test\TestSelectGroupByAndConstant\TestSelectGroupByAndConstant\ApplicationWebService.cs // the safe way to hint we need to talk PHP dialect QueryExpressionBuilder.Dialect = QueryExpressionBuilderDialect.MySQL; QueryExpressionBuilder.WithConnection = y => { Console.WriteLine("enter WithConnection"); //var DataSource = "file:xApplicationPerformance.xlsx.sqlite"; var cc0 = new MySQLConnection( new System.Data.MySQL.MySQLConnectionStringBuilder { //Database = UserID = "root", Server = "127.0.0.1", //SslMode = MySQLSslMode.VerifyFull //ConnectionTimeout = 3000 }.ToString() //new MySQLConnectionStringBuilder { DataSource = "file:PerformanceResourceTimingData2.xlsx.sqlite" }.ToString() ); // Additional information: Authentication to host '' for user '' using method 'mysql_native_password' failed with message: Access denied for user ''@'asus7' (using password: NO) // Additional information: Unable to connect to any of the specified MySQL hosts. cc0.Open(); #region use db { //var a = Assembly.GetExecutingAssembly().GetName(); // SkipUntilIfAny ??? //var QDataSource = a.Name + ":" + DataSource.SkipUntilIfAny("file:").TakeUntilIfAny(".xlsx.sqlite"); var QDataSource = "TestAppEngineOrderByThenGroupBy"; // QDataSource.Length = 76 var QLengthb = QDataSource.Length; // Database 64 cc0.CreateCommand("CREATE DATABASE IF NOT EXISTS `" + QDataSource + "`").ExecuteScalar(); cc0.CreateCommand("use `" + QDataSource + "`").ExecuteScalar(); } #endregion y(cc0); // jsc java does the wrong thing here cc0.Close(); //cc0.Dispose(); Console.WriteLine("exit WithConnection"); }; #endregion }
private static void PrepareCommand(MySQLCommand cmd, MySQLConnection conn, MySQLTransaction trans, string cmdText, MySQLParameter[] cmdParms) { if (conn.State != ConnectionState.Open) conn.Open(); cmd.Connection = conn; cmd.CommandText = cmdText; if (trans != null) cmd.Transaction = trans; cmd.CommandType = CommandType.Text;//cmdType; if (cmdParms != null) { foreach (MySQLParameter parameter in cmdParms) { if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) && (parameter.Value == null)) { parameter.Value = DBNull.Value; } cmd.Parameters.Add(parameter); } } conn.Close(); }
static void Main(string[] args) { // while (true) // { try { StreamReader objReader = new StreamReader("setting.ini"); string sLine = ""; ArrayList arrText = new ArrayList(); while (sLine != null) { sLine = objReader.ReadLine(); if (sLine != null) arrText.Add(sLine); } objReader.Close(); // foreach (string sOutput in arrText) // dbconn = sOutput; //MySQLConnection conn = new MySQLConnection(new MySQLConnectionString("192.168.234.129", "qqnotic", "toryzen", "q1w2e3r4").AsString);//实例化一个连接对象其中myquest为数据库名,root为数据库用户名,amttgroup为数据库密码 MySQLConnection conn = new MySQLConnection(new MySQLConnectionString(arrText[0].ToString(), arrText[1].ToString(), arrText[2].ToString(), arrText[3].ToString()).AsString);//实例化一个连接对象其中myquest为数据库名,root为数据库用户名,amttgroup为数据库密码 conn.Open(); MySQLCommand commn = new MySQLCommand("set names gb2312;", conn); commn.ExecuteNonQuery(); MySQLCommand cmds = new MySQLCommand("select * from qqnotic where isok = 0 limit 1", conn); MySQLDataReader reader = cmds.ExecuteReaderEx(); while (reader.Read()) { int userid = int.Parse(reader["userid"].ToString()); //用户id int checktype = int.Parse(reader["btype"].ToString()); //业务类型 MySQLCommand cmdname = new MySQLCommand("select * from qqname where id = " + userid, conn); MySQLDataReader readername = cmdname.ExecuteReaderEx(); while (readername.Read()) { qq = int.Parse(readername["qqnum"].ToString()); //qq号码 qqname = (string)readername["qqname"]; //qq昵称 realname = (string)readername["realname"]; //用户真名 } bbtype = "光宇信息中心通知"; //通知标题 bbcontent = (string)reader["content"]; //通知内容 /* 若指定通知类型 */ if (checktype != 0) { MySQLCommand cmdtype = new MySQLCommand("select * from btype where id = " + checktype, conn); MySQLDataReader btype = cmdtype.ExecuteReaderEx(); while (btype.Read()) { bbtype = (string)btype["type"]; //通知标题 bbcontent = (string)btype["content"]; //通知内容 } } System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); int timeStamp = (int)(System.DateTime.Now - startTime).TotalSeconds; MySQLCommand excmds = new MySQLCommand("UPDATE `qqnotic`.`qqnotic` SET `isok` = '1',`extime` = " + timeStamp + " WHERE `qqnotic`.`id` =" + reader["id"], conn); excmds.ExecuteNonQuery(); //写入系统时间 notis = bbtype + ":\n" + realname + "您好," + bbcontent; Console.WriteLine(System.DateTime.Now + "向用户" + realname + "(" + qq + ") 发送一条信息!"); } conn.Close(); } catch { Exception e; } if (qq != 0 && notis != "") { try { Clipboard.Clear(); Clipboard.SetDataObject(notis,true); } catch { Exception e; } const int WM_CHAR = 0x0102; const int WM_KEYDOWN = 0x0100; const int WM_PASTE = 0x0302; const int WM_SETTEXT = 0x000C; const int WM_Close = 0x0010; string[] cmd = new string[] { "start tencent://message/?uin=" + qq + "&Site=gyyx.cn&Menu=yes" }; Cmd(cmd); Thread.Sleep(1000); EnumWindows(PrintWindow, IntPtr.Zero); string tr = notis; IntPtr hwndCalc = hander; //ShowWindow(hwndCalc,1); PostMessage(hwndCalc, WM_PASTE, 0, 0); Thread.Sleep(500); PostMessage(hwndCalc, WM_KEYDOWN, 13, 0); Thread.Sleep(500); //PostMessage(hwndCalc, WM_KEYDOWN, 27, 0); PostMessage(hwndCalc, WM_Close, 0, 0); Thread.Sleep(1000); qq = 0; notis = ""; } // else { Thread.Sleep(6000); } // } }
public static object ExecuteScalar(string SQLString) { using (MySQLConnection connection = new MySQLConnection(connectionString)) { using (MySQLCommand cmd = new MySQLCommand(SQLString, connection)) { try { connection.Open(); object obj = cmd.ExecuteScalar(); if (Object.Equals(obj, null) || (Object.Equals(obj, System.DBNull.Value))) { return null; } else { return obj; } } catch (MySQLException e) { connection.Close(); throw e; } } } }
public static MySQLDataReader ExecuteReader(string SQLString, params MySQLParameter[] cmdParms) { MySQLConnection connection = new MySQLConnection(connectionString); MySQLCommand cmd = new MySQLCommand(); MySQLDataReader myReader = null; try { PrepareCommand(cmd, connection, null, SQLString, cmdParms); myReader = cmd.ExecuteReaderEx(); cmd.Parameters.Clear(); return myReader; } catch (MySQLException e) { throw e; } finally { myReader.Close(); cmd.Dispose(); connection.Close(); } }
//执行SQL语句,返回影响的记录数 //<param name="sqlString">sql语句</param> public static int ExecuteNonQuery(string SQLString) { using (MySQLConnection connection = new MySQLConnection(connectionString)) { using (MySQLCommand cmd = new MySQLCommand(SQLString, connection)) { try { connection.Open(); MySQLCommand setformat = new MySQLCommand("set names gb2312", connection); setformat.ExecuteNonQuery(); setformat.Dispose(); int rows = cmd.ExecuteNonQuery(); return rows; } catch (MySQLException e) { connection.Close(); throw e; } } } }
public static ToolboxCategoryItems loadUserbox() { MySQLConnection DBConn = new MySQLConnection(new MySQLConnectionString(Configuration.getDBIp(), "workflow", Configuration.getDBUsername(), Configuration.getDBPassword()).AsString); if (DBConn != null) { try { DBConn.Open(); string sql1 = "set names gb2312"; MySQLCommand DBComm = new MySQLCommand(sql1, DBConn); //設定下達 command DBComm.ExecuteNonQuery(); DBComm.Dispose(); string sql = "select * from tb_user"; MySQLDataAdapter mda = new MySQLDataAdapter(sql, DBConn); DataTable UserDataTable = new DataTable(); mda.Fill(UserDataTable); DBConn.Close(); loadSystemIcon(); ToolboxCategoryItems toolboxCategoryItems = new ToolboxCategoryItems(); ToolboxCategory users = new System.Activities.Presentation.Toolbox.ToolboxCategory("系统工作人员"); foreach (DataRow dr in UserDataTable.Rows) { //byte[] temp = Encoding.Default.GetBytes(dr["User_Name"].ToString()); //temp = System.Text.Encoding.Convert(Encoding.GetEncoding("utf8"), Encoding.GetEncoding("gb2312"), temp); //string username = Encoding.Default.GetString(temp); //ToolboxItemWrapper User = new ToolboxItemWrapper(typeof(Wxwinter.BPM.WFDesigner.User), username); ToolboxItemWrapper User = new ToolboxItemWrapper(typeof(Wxwinter.BPM.WFDesigner.User), dr["User_Name"].ToString()); users.Add(User); } toolboxCategoryItems.Add(users); parentWindow.statusInfo.Text = ""; return toolboxCategoryItems; } catch (Exception e) { parentWindow.statusInfo.Text = "数据库连接失败,请检查网络设置和数据库连接配置"; return null; } } else { return null; } }
// https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201510/20151006/xlsx // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150911/mysql //Implementation not found for type import : //type: System.Data.SQLite.SQLiteCommand //method: Void .ctor(System.String, System.Data.SQLite.SQLiteConnection) //Did you forget to add the [Script] attribute? //Please double check the signature! //assembly: W:\XSLXAssetWithXElement.ApplicationWebService.exe //type: XSLXAssetWithXElement.Data.Book1+Sheet1+Queries, XSLXAssetWithXElement.ApplicationWebService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null //offset: 0x0006 // method:System.Threading.Tasks.Task Create(System.Data.SQLite.SQLiteConnection) static ApplicationWebService() { // ex = {"Could not load file or assembly 'ScriptCoreLib.Ultra, Version=4.5.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.":"ScriptCoreLib.Ultra, Version=4.5.0.0, Culture=neutral, PublicKeyToken=null"} //{ var r = typeof(ScriptCoreLib.Shared.Data.Diagnostics.WithConnectionLambda); } { var r = typeof(System.Data.SQLite.SQLiteConnection); } { var r = typeof(ScriptCoreLib.Library.StringConversions); } #if DEBUG #region QueryExpressionBuilder.WithConnection QueryExpressionBuilder.WithConnection = y => { // jsc should imply it? var cc = new SQLiteConnection( new SQLiteConnectionStringBuilder { // "Z:\jsc.svn\examples\javascript\appengine\XSLXAssetWithXElement\XSLXAssetWithXElement\bin\Debug\staging\XSLXAssetWithXElement.ApplicationWebService\staging.net.debug\Book1.xlsx.sqlite" DataSource = "file:Book1.xlsx.sqlite" }.ToString() ); cc.Open(); y(cc); cc.Dispose(); }; #endregion #else #region MySQLConnection // X:\jsc.svn\examples\javascript\LINQ\test\TestSelectGroupByAndConstant\TestSelectGroupByAndConstant\ApplicationWebService.cs // the safe way to hint we need to talk PHP dialect QueryExpressionBuilder.Dialect = QueryExpressionBuilderDialect.MySQL; QueryExpressionBuilder.WithConnection = y => { Console.WriteLine("enter WithConnection"); //var DataSource = "file:xApplicationPerformance.xlsx.sqlite"; var cc0 = new MySQLConnection( new System.Data.MySQL.MySQLConnectionStringBuilder { //Database = UserID = "root", Server = "127.0.0.1", //SslMode = MySQLSslMode.VerifyFull //ConnectionTimeout = 3000 }.ToString() //new MySQLConnectionStringBuilder { DataSource = "file:PerformanceResourceTimingData2.xlsx.sqlite" }.ToString() ); // Additional information: Authentication to host '' for user '' using method 'mysql_native_password' failed with message: Access denied for user ''@'asus7' (using password: NO) // Additional information: Unable to connect to any of the specified MySQL hosts. cc0.Open(); #region use db { //var a = Assembly.GetExecutingAssembly().GetName(); // SkipUntilIfAny ??? //var QDataSource = a.Name + ":" + DataSource.SkipUntilIfAny("file:").TakeUntilIfAny(".xlsx.sqlite"); var QDataSource = "XSLXAssetWithXElement"; // QDataSource.Length = 76 var QLengthb = QDataSource.Length; // Database 64 cc0.CreateCommand("CREATE DATABASE IF NOT EXISTS `" + QDataSource + "`").ExecuteScalar(); cc0.CreateCommand("use `" + QDataSource + "`").ExecuteScalar(); } #endregion y(cc0); // jsc java does the wrong thing here cc0.Close(); //cc0.Dispose(); Console.WriteLine("exit WithConnection"); }; #endregion #endif }