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).
            Asked
            
        
        
            Active
            
        
            Viewed 769 times
        
    0
            
            
        - 
                    Use ado.net, if you don't want to use EF – Deepak Mishra May 04 '20 at 15:29
 - 
                    I cannot use any ORM. – Jupss May 04 '20 at 15:31
 - 
                    use stored procedures and access the database using the context – JamesS May 04 '20 at 15:33
 - 
                    ADO.Net is not an ARM https://stackoverflow.com/questions/35444487/how-to-use-sqlclient-in-asp-net-core – Deepak Mishra May 04 '20 at 15:34
 
1 Answers
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