gpt4 book ai didi

c# - 在 SELECT 语句中从 cookie 获取值

转载 作者:太空宇宙 更新时间:2023-11-03 20:37:19 24 4
gpt4 key购买 nike

我正在尝试在 SELECT sql 语句中检索 cookie 值,这是我的代码

      SELECT orders.order_id, orders.order_date, orders.payment_type, 
orders.cardnumber, packages.Package_name, orders.package_id,
packages.package_price
FROM orders INNER JOIN packages ON orders.package_id = packages.Package_ID
WHERE (orders.username = '**value here**')

我需要在 orders.username = '**value here**' 中检索 cookie 的值

我的 cookie 是:Request.Cookies["Username"].Value

最佳答案

使用参数化查询,cookie 的值是传入的参数。

string sql = "SELECT orders.order_id, 
orders.order_date,
orders.payment_type,
orders.cardnumber,
packages.Package_name,
orders.package_id,
packages.package_price
FROM orders INNER JOIN packages ON orders.package_id = packages.Package_ID
WHERE (orders.username = @UserName)"

using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(sql, connection);
command.Parameters.Add("@ID", SqlDbType.VarChar, 200);
...
}

关于c# - 在 SELECT 语句中从 cookie 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4534567/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com