gpt4 book ai didi

C# SQL参数查询带in

转载 作者:行者123 更新时间:2023-11-30 15:06:27 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Parameterizing a SQL IN clause?

我有以下代码:

var myCommand = new SqlCommand();
myCommand.Parameters.Add("@username", SqlDbType.NVarChar);
myCommand.Parameters["@username"].Value = username;
return _dbConnection.ExecuteQuery("Select * from customer where username = @username");

现在我需要为更多值调整查询。我想做这样的事情:

var myCommand = new SqlCommand();
foreach (string username in usernames){
myCommand.Parameters.Add("@username", SqlDbType.NVarChar);
myCommand.Parameters["@username"].Value = username;
}
return _dbConnection.ExecuteQuery("Select * from customer where username in @username");

这可能吗?怎么办?

谢谢!

BR 斯特凡

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