public override ProductInfoList _GetProducts() { ProductInfoList res = new ProductInfoList(); using (MySqlConnection conn = new MySqlConnection(GetConnectionString())) { using (MySqlCommand cmd = new MySqlCommand(QRY_GET_PRODUCTS, conn)) { using (MySqlDataAdapter da = new MySqlDataAdapter(cmd)) { DataTable tbl = new DataTable("product"); try { da.Fill(tbl); foreach (DataRow row in tbl.Rows) { long productId = Convert.ToInt64(row["product_id"]); string name = Convert.ToString(row["name"]); string description = Convert.ToString(row["description"]); int credits = Convert.ToInt32(row["credits"]); string extra = Convert.ToString(row["extra"]); string productPlan = Convert.ToString(row["product_plan"]); res.Add(new ProductInfo(productId, name, description, credits, extra, productPlan)); } } catch (MySqlException ex) { Logger.Instance.Write(LogLevel.Error, ex, "GetProducts<MySqlException>"); } finally { conn.Close(); } } } } return res; }
public ProductInfoList GetProducts() { ProductInfoList res = new ProductInfoList(); using (NpgsqlConnection conn = new NpgsqlConnection(GetConnectionString())) { using (NpgsqlCommand cmd = new NpgsqlCommand(QRY_GET_PRODUCTS, conn)) { using (NpgsqlDataAdapter da = new NpgsqlDataAdapter(cmd)) { DataTable tbl = new DataTable("product"); try { da.Fill(tbl); foreach (DataRow row in tbl.Rows) { int productId = Convert.ToInt32(row["product_id"]); string name = Convert.ToString(row["name"]); string description = Convert.ToString(row["description"]); int credits = Convert.ToInt32(row["credits"]); res.Add(new ProductInfo(productId, name, description, credits)); } } catch (NpgsqlException ex) { Logger.Instance.Write (TrackProtect.Logging.LogLevel.Error, ex, "GetProducts<NpgsqlException>"); } finally { conn.Close(); } } } } return res; }