public int AddProduct(string ProductCode, string ProductName, decimal CurrentPrice, decimal OriginalPrice, string PackingUnit, string Specification, string PromotionalPrice, int CompanyID, string PromotionalStart, string PromotionalEnd) { string strSql = "INSERT INTO tblProduct(ProductCode,CategoryID,ProductName,CurrentPrice,OriginalPrice,StatusCode,CompanyID,PackingUnit,OrderNum,PromotionalPrice,PromotionalStart,PromotionalEnd) VALUES(@ProductCode,1,@ProductName,@CurrentPrice,@OriginalPrice,'NORMAL',@CompanyID,@PackingUnit,0,@PromotionalPrice,@PromotionalStart,@PromotionalEnd)"; SqlCommand cmd = new SqlCommand(strSql, conn); cmd.Parameters.AddWithValue("@ProductCode", ProductCode); cmd.Parameters.AddWithValue("@ProductName", ProductName); cmd.Parameters.AddWithValue("@CurrentPrice", CurrentPrice); cmd.Parameters.AddWithValue("@OriginalPrice", OriginalPrice); cmd.Parameters.AddWithValue("@PackingUnit", PackingUnit); cmd.Parameters.AddWithValue("@Specification", Specification); if (PromotionalPrice.Length == 0) { cmd.Parameters.AddWithValue("@PromotionalPrice", DBNull.Value); } else { cmd.Parameters.AddWithValue("@PromotionalPrice", float.Parse(PromotionalPrice)); } if (PromotionalStart.Length == 0) { cmd.Parameters.AddWithValue("@PromotionalStart", DBNull.Value); } else { cmd.Parameters.AddWithValue("@PromotionalStart", Convert.ToDateTime(PromotionalStart)); } if (PromotionalEnd.Length == 0) { cmd.Parameters.AddWithValue("@PromotionalEnd", DBNull.Value); } else { cmd.Parameters.AddWithValue("@PromotionalEnd", Convert.ToDateTime(PromotionalEnd)); } cmd.Parameters.AddWithValue("@CompanyID", CompanyID); conn.Open(); try { return cmd.ExecuteNonQuery(); } finally { conn.Close(); } }