protected void Button1_Click(object sender, EventArgs e) { using (var con = new SqlConnection(conStr)) { var cmd = con.CreateCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "Select * From ProductTable"; con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); con.Close(); List <ProductCls> list = new List <ProductCls>(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { ProductCls obj = new ProductCls(); obj.Id = Convert.ToInt32(dt.Rows[i]["Id"].ToString()); obj.ProductName = dt.Rows[i]["ProductName"].ToString(); obj.Price = Convert.ToDecimal(dt.Rows[i]["Price"].ToString()); obj.TotalAmount = Convert.ToDecimal(dt.Rows[i]["TotalAmount"].ToString()); obj.ProductImage = dt.Rows[i]["ProductImage"].ToString(); list.Add(obj); } Session["ReportData"] = list; Response.Redirect("ProductReportViewer.aspx"); } } }
public static List <ProductCls> productCls() { List <ProductCls> products = new List <ProductCls>(); using (var con = new SqlConnection(conStr)) { var cmd = con.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * from ProductTable"; con.Open(); var rdr = cmd.ExecuteReader(); while (rdr.Read()) { ProductCls obj = new ProductCls(); obj.Id = Convert.ToInt32(rdr["Id"].ToString()); obj.ProductName = rdr["ProductName"].ToString(); obj.ProductQTY = Convert.ToDecimal(rdr["ProductQTY"].ToString()); obj.Price = Convert.ToDecimal(rdr["Price"].ToString()); obj.TotalAmount = Convert.ToDecimal(rdr["TotalAmount"].ToString()); obj.ProductImage = rdr["ProductImage"].ToString(); products.Add(obj); } } return(products); }
protected void Button1_Click(object sender, EventArgs e) { string img = Path.GetFileName(FileUpload1.PostedFile.FileName); FileUpload1.SaveAs(Server.MapPath("~/Images/") + img); ProductCls obj = new ProductCls(); obj.ProductName = TextBox1.Text; obj.ProductQTY = Convert.ToDecimal(TextBox2.Text); obj.Price = Convert.ToDecimal(TextBox3.Text); obj.TotalAmount = Convert.ToDecimal(TextBox4.Text); obj.ProductImage = "Images/" + img; ProductClsGetWway1.InsertProduct(obj.ProductName, obj.ProductQTY, obj.Price, obj.TotalAmount, obj.ProductImage); Response.Redirect("~/Product1"); }