private bool Reinsert(ref CPic_Pipe pipe) { MySqlDataReader reader; MySqlCommand cmd = null; string strcmd = "INSERT INTO [Pic_Pipe]([PipeID],[PicPath]) values(" + pipe.PipeID + " ,'" + pipe.PicPath + "')"; try { connect.Open(); cmd = new MySqlCommand(); cmd.Connection = connect; cmd.CommandType = CommandType.Text; cmd.CommandText = strcmd; strcmd = "SELECT MAX([ID]) AS MAXID FROM [Pic_Pipe]"; cmd.ExecuteNonQuery(); cmd.CommandText = strcmd; reader = cmd.ExecuteReader(); reader.Read(); pipe.ID = Convert.ToInt32(reader[0].ToString()); } catch (System.Exception ex) { Console.WriteLine("Pipe of Pic error : " + ex.Message); return false; } Console.WriteLine("Success!"); return true; }
public bool Delete_Pic_Pipe(CPic_Pipe pipe) { List<string> listcmd = new List<string>(); try { string cmd = "DELETE * FROM [Pic_Pipe] where ID = " + pipe.ID; listcmd.Add(cmd); ExectueCmd(listcmd); } catch (System.Exception ex) { Console.WriteLine("Pipe of Pic error : " + ex.Message); return false; } return true; }
private List<CPic_Pipe> Select(string cmd) { List<CPic_Pipe> listpipe = new List<CPic_Pipe>(); MySqlCommand com; MySqlDataReader reader; try { if (ConnectionState.Closed == connect.State) connect.Open(); com = new MySqlCommand(cmd, connect); reader = com.ExecuteReader(); while (reader.Read()) { CPic_Pipe pipe = new CPic_Pipe(); int i = 0; string tmp; pipe.ID = Convert.ToInt32(reader[i++].ToString()); tmp = reader[i++].ToString(); if (tmp != null && tmp.Length > 0) pipe.PipeID = Convert.ToInt32(tmp); pipe.PicPath = reader[i++].ToString(); listpipe.Add(pipe); } } catch (System.Exception ex) { Console.WriteLine("Pipe of Pic error : " + ex.Message); return null; } finally { if(connect!=null) connect.Close(); } return listpipe; }
public bool Insert_Pic_Pipe(ref CPic_Pipe pipe) { MySqlDataReader reader; MySqlCommand cmd = null; string strcmd = "INSERT INTO [Pic_Pipe]([PipeID],[PicPath]) values("+pipe.PipeID+" ,'"+pipe.PicPath+"')"; try { if (ConnectionState.Closed == connect.State) { connect.Open(); cmd = new MySqlCommand(); count = 0; } else if (count >= NUMBER) { count = 0; connect.Close(); mysqlcmd = new MySqlCommand(); cmd = mysqlcmd; connect.Open(); } else { count++; cmd = mysqlcmd.Clone(); } cmd.Connection = connect; cmd.CommandType = CommandType.Text; cmd.CommandText = strcmd; strcmd = "SELECT MAX([ID]) AS MAXID FROM [Pic_Pipe]"; cmd.ExecuteNonQuery(); cmd.CommandText = strcmd; reader = cmd.ExecuteReader(); reader.Read(); pipe.ID = Convert.ToInt32(reader[0].ToString()); } catch (System.Exception ex) { Console.WriteLine("Pipe of Pic error : "+ex.Message); Console.WriteLine("Reinsert Pic:"); connect.Close(); return Reinsert(ref pipe); } finally { //connect.Close(); } return true; }