using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data .SqlClient ; using System.Data ;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { String sqlconn = "Server=.; DataBase=db; Integrated Security=SSPI "; string sql = "select top 10 * from table";
SqlConnection myConnection = new SqlConnection(sqlconn);// 创建数据库连接实例
myConnection.Open(); //打开数据库
SqlCommand myCommand = new SqlCommand(sql, myConnection);//创建sql的实例,执行一个sql
SqlDataAdapter Adapter = new SqlDataAdapter();//创建一个sql数据适配器 Adapter.SelectCommand = myCommand;//属性设置为 从数据源中检索记录
DataSet myDs = new DataSet(); //创建数据集实例 Adapter.Fill(myDs);//填充数据集