111,126
社区成员
发帖
与我相关
我的任务
分享
//实例化Connection对象
SqlConnection connection = new SqlConnection("Data Source=(local);Initial Catalog=AspNetStudy;Persist Security Info=True;User ID=sa;Password=sa");
//实例化Command对象
SqlCommand command = new SqlCommand("select count(1) as 男性人数 from UserInfo where sex=1", connection);
//打开Connection对象
connection.Open();
//执行SQL语句
int count = int.Parse(command.ExecuteScalar().ToString());
//关闭Connection对象
connection.Close();