protected void Page_Load(object sender, EventArgs e)
{
//创建连接字符串
string strConn = "data source=localhost;initial catalog=Northwind;user id=sa;password=sa";
SqlConnection myConn = new SqlConnection(strConn);
string strSQL = "SELECT Top 5 CategoryID,CategoryName,Description From Categories";
//创建SqlCommand对象,其SQl文本为strSQL
SqlCommand myCommand = new SqlCommand(strSQL, myConn);
myConn.Open();
myGv.DataSource = myCommand.ExecuteReader();
myGv.DataBind();
myConn.Close();
}
{
//创建连接字符串
string strConn = "data source=localhost;initial catalog=Northwind;user id=sa;password=sa";
SqlConnection myConn = new SqlConnection(strConn);
string strSQL = "SELECT Top 5 CategoryID,CategoryName,Description From Categories";
//创建SqlCommand对象,其SQl文本为strSQL
SqlCommand myCommand = new SqlCommand(strSQL, myConn);
myConn.Open();
myGv.DataSource = myCommand.ExecuteReader();
myGv.DataBind();
myConn.Close();
}