http://blog.sina.com.tw/myvufzbi/article.php?pbgid=91238&entryid=595441
把資料展現到畫面上
ExecuteReader
//建立連線
SqlConnection conn;
conn = new SqlConnection("data source = EasyFlow;initial catalog = EFNET;user id =sa;password = XXX");
conn.Open();
SqlConnection conn;
conn = new SqlConnection("data source = EasyFlow;initial catalog = EFNET;user id =sa;password = XXX");
conn.Open();
//下指令
SqlCommand cmd;
cmd = new SqlCommand("select dept as 部門,empname as 員工名稱,empno as 員工代號,extension as 分機,phs as PHS from extension where deptno like @empno", conn);
cmd.Parameters.Add("@empno", SqlDbType.NVarChar).Value = txt_what.Text.Trim() + "%";
SqlCommand cmd;
cmd = new SqlCommand("select dept as 部門,empname as 員工名稱,empno as 員工代號,extension as 分機,phs as PHS from extension where deptno like @empno", conn);
cmd.Parameters.Add("@empno", SqlDbType.NVarChar).Value = txt_what.Text.Trim() + "%";
//讀取到中介
SqlDataReader dr;
dr = cmd.ExecuteReader();
SqlDataReader dr;
dr = cmd.ExecuteReader();
//仲介資料給GridView去顯示
GridView.DataSource = dr;
GridView.DataBind();
GridView.DataSource = dr;
GridView.DataBind();
//若要讀取仲介的每一筆資料並丟給DropDownList
while (dr.Read())
{
DropDownList.Items.Add(dr["dept"].ToString()); //dr["dept"].ToString() 是dr的dept欄位資料
}
while (dr.Read())
{
DropDownList.Items.Add(dr["dept"].ToString()); //dr["dept"].ToString() 是dr的dept欄位資料
}
沒有留言:
張貼留言