public MySqlCommand GetAddCommand(Product obj) { MySqlCommand cmd = new MySqlCommand(); string sql="insert into testdb.product(product_num,product_name,price,status,hello) values(?product_num, ?product_name, ?price, ?status, ?hello)"; cmd.CommandText = sql; cmd.Parameters.Add(new MySqlParameter("?product_num", SqlDataUtil.ToDBNullValue(obj.Product_Num))); cmd.Parameters.Add(new MySqlParameter("?product_name", SqlDataUtil.ToDBNullValue(obj.Product_Name))); cmd.Parameters.Add(new MySqlParameter("?price", SqlDataUtil.ToDBNullValue(obj.Price))); cmd.Parameters.Add(new MySqlParameter("?status", SqlDataUtil.ToDBNullValue(obj.Status))); cmd.Parameters.Add(new MySqlParameter("?hello", SqlDataUtil.ToDBNullValue(obj.Hello))); return cmd; }
public MySqlCommand GetUpdateCommand(Product obj) { MySqlCommand cmd = new MySqlCommand(); string sql="update testdb.product set price=?price,status=?status,hello=?hello where product_num=?product_num and product_name=?product_name "; cmd.CommandText = sql; cmd.Parameters.Add(new MySqlParameter("?product_num", SqlDataUtil.ToDBNullValue(obj.Product_Num))); cmd.Parameters.Add(new MySqlParameter("?product_name", SqlDataUtil.ToDBNullValue(obj.Product_Name))); cmd.Parameters.Add(new MySqlParameter("?price", SqlDataUtil.ToDBNullValue(obj.Price))); cmd.Parameters.Add(new MySqlParameter("?status", SqlDataUtil.ToDBNullValue(obj.Status))); cmd.Parameters.Add(new MySqlParameter("?hello", SqlDataUtil.ToDBNullValue(obj.Hello))); return cmd; }
public Product FindByKey(string product_num,string product_name) { MySqlCommand cmd = GetFindCommand(product_num,product_name); DataSet dataSet = SqlUtil.ExecuteQuery(cmd); if (dataSet.Tables[0].Rows.Count < 1) { return null; } DataRow dr = dataSet.Tables[0].Rows[0]; Product obj = new Product(); DataUtil.DataRowToObject(dr,obj); return obj; }
public int Update(Product obj) { MySqlCommand cmd = GetUpdateCommand(obj); return (int)SqlUtil.ExecuteNonQuery(cmd); }
public static int Add(Product obj) { return helper.Add(obj); }