连接数据库与查询

protected void Page_Load(object sender, EventArgs e)
{
SqlConnection myconn = new SqlConnection();
string mystr = "Data source=.;Database=test;User ID=sa;Password=123456;";
myconn.ConnectionString = mystr;
myconn.Open();
SqlCommand mycmd =new SqlCommand("SELECT xingming FROM xuesheng where xuehao=2",myconn);
var hhh=mycmd.ExecuteScalar();
Response.Write(hhh);
}

原文地址:https://www.cnblogs.com/thybk/p/7298203.html