我有一个名为"Products“的数据库表。该表包含带有一些字段的产品,如"ProductId“、"ProductName”和"ProductPrice“。我想创建一个函数,通过ProductId获取表中某行的值,这样我就可以将这些值存储在cookie中。如何仅使用ProductId作为参数来获取一行"Products“表?(没有实体框架)。
发布于 2020-05-04 23:54:28
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()));
}
}https://stackoverflow.com/questions/61595752
复制相似问题