gpt4 book ai didi

c#.Net : Execute two SQL statements at a time

转载 作者:行者123 更新时间:2023-11-30 19:59:47 27 4
gpt4 key购买 nike

请问有没有办法执行多条SQL语句。就像我想获得计数和值(value)一样。我如何在 C# 中执行此操作?

查询 1:

cmd = new SqlCommand("select count(*) from tblStock where prodName=@prodName", con); // to get count

查询 2:

cmd = new SqlCommand("select quantity from tblStock where prodName=@prodName", con);// to get qty

int count, qty;

try
{
con.Open();
count = (Int32)cmd.ExecuteScalar(); //returns null if doesnt exist
qty = (Int32)cmd.ExecuteScalar();

}

这可能吗?

最佳答案

您不能只在一个选择查询中同时选择两个值吗?

cmd = new SqlCommand("select quantity, count(*) from tblStock where prodName=@prodName", con);

关于c#.Net : Execute two SQL statements at a time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22975025/

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