我如何在变量中存储sql查询的值 [英] how can i store values of sql query in variable
本文介绍了我如何在变量中存储sql查询的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将sql查询的值存储在变量中
how can i store values of sql query in variable
推荐答案
您可以使用SqlCommand类的ExecuteScalar方法.示例代码为:
You can use ExecuteScalar method of SqlCommand class. Sample code is:
SqlConnection connection = new SqlConnection(myConnectionString);
SqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "SELECT count(EmpID) FROM Employee";
int result = ((int)cmd.ExecuteScalar());
connection.Close();
这篇关于我如何在变量中存储sql查询的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文