首页 > 数据库技术 > 详细

Visual Studio中访问SQL数据库的代码

时间:2015-12-17 19:12:22      阅读:223      评论:0      收藏:0      [点我收藏+]
string strCon = "Data Source=.;Initial Catalog=Northwind;uid=sa;pwd=Daniel";
using (SqlConnection con = new SqlConnection(strCon))
{
using (SqlCommand cmd = con.CreateCommand())
{
string strSql = "select count(*) from Customers";
cmd.CommandText = strSql;
con.Open();
int intCount = Int32.Parse(cmd.ExecuteScalar().ToString()); //ExecuteScaler();
Console.WriteLine(intCount);

cmd.CommandText = "select * from Customers";
string strS = cmd.ExecuteScalar().ToString(); //ExecuteScalar() 返回结果集的首行首列
Console.WriteLine(strS); //ALFKI 返回结果集的首行首列

}
}
Console.ReadKey();

 

Visual Studio中访问SQL数据库的代码

原文:http://www.cnblogs.com/wingfly/p/5054784.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!