您的位置:首页 > 其它

学习笔记--ado.net 数据绑定

2012-03-19 17:55 369 查看
protected void Page_Load(object sender, EventArgs e)

{SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=teachers;Integrated Security=True;");

SqlDataAdapter da = new SqlDataAdapter("select*from tea_info where s_sex='boy'", conn);

DataSet ds = new DataSet();

da.Fill(ds, "result");

this.DropDownList1.DataSource = ds.Tables["result"];

this.DropDownList1.DataTextField = "s_name";

this.DropDownList1.DataBind();}

两种方法的不同,细细体会。

/* SqlConnection conn = new SqlConnection("sever=.;database=teachers;integrated security=true");

conn.Open();

SqlCommand cmd = new SqlCommand("select*form tea_info",conn);

SqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())

{

this.DropDownList1.Items.Add(dr["s_name"].ToString());

}

conn.Close(); */
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: