标签:
相关知识:
代码示例:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.Data; 7 using System.Data.SqlClient; 8 9 namespace ConsoleApplication3 10 { 11 class Program 12 { 13 static void Main(string[] args) 14 { 15 string strConn = @"server=Joe-PC;database=AdventureWorks_WroxSSRS2012;uid=sa;pwd=root"; 16 SqlConnection conn = new SqlConnection(strConn); 17 18 string strCmd = "SELECT COUNT(*) FROM Production.ProductCategory"; 19 SqlCommand cmd = new SqlCommand(strCmd, conn); 20 21 conn.Open(); 22 23 int count = Convert.ToInt32(cmd.ExecuteScalar());// ExecuteScalar返回一个object类型 24 25 Console.WriteLine("共有{0}行数据。", count); 26 27 conn.Close(); 28 } 29 } 30 }
ADO.NET快速入门——利用Command对象的ExecuteScalar()方法返回一个数据值
标签:
原文地址:http://www.cnblogs.com/chenguangqiao/p/4340908.html