//建立連線
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() + "%";
//讀取到中介
SqlDataReader dr;
dr = cmd.ExecuteReader();
//仲介資料給GridView去顯示
GridView.DataSource = dr;
GridView.DataBind();
//若要讀取仲介的每一筆資料並丟給DropDownList
while (dr.Read())
{
DropDownList.Items.Add(dr["dept"].ToString()); //dr["dept"].ToString() 是dr的dept欄位資料
}
全站熱搜
留言列表