0

i've got an database table called "Products". The table contains products with a few fields like "ProductId", "ProductName" and "ProductPrice". I want to make an function that gets the value of a row inside my table by its ProductId so I can store these values inside a cookie. How do I get a row of table "Products" just using a ProductId as parameter? (Without Entity Framework).

Jupss
  • 7
  • 4

1 Answers1

0
using (SqlConnection con = new SqlConnection("data source=xxxx;user id=sa;password=xxxxx;integrated security=yes"))
            {
                SqlDataAdapter da = new SqlDataAdapter("select * from Products where ProductId=" + ProductId);
                DataSet ds = new DataSet();
                da.Fill(ds);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    Console.WriteLine(string.Format("ProductName - {0} and ProductPrice -{1}", ds.Tables[0].Rows[0]["ProductName"].ToString(),
                        ds.Tables[0].Rows[0]["ProductPrice"].ToString()));
                }
            }
Always_a_learner
  • 1,254
  • 1
  • 8
  • 16