看板 C_Sharp 關於我們 聯絡資訊
private void Page_Load(object sender, System.EventArgs e) { SqlConnection conn = new SqlConnection("server=172.17.7.16;uid=sa;pwd=;database=cs"); SqlDataAdapter cmd = new SqlDataAdapter("select * from cs95",conn); DataSet ds = new DataSet(); cmd.Fill(ds,"cs95"); this.DataGrid1.DataSource= ds.Tables["cs95"]; this.DataGrid1.DataBind(); } protected void sort (object obj, DataGridSortCommandEventArgs e){ SqlConnection conn = new SqlConnection("server=172.17.7.16;uid=sa;pwd=;database=cs"); SqlDataAdapter cmd = new SqlDataAdapter("select * from cs95",conn); DataSet ds = new DataSet(); cmd.Fill(ds,"cs95"); DataView dv = new DataView(ds.Tables["cs95"]); dv.Sort=e.SortExpression.ToString(); this.DataGrid1.DataSource=dv; this.DataGrid1.DataBind(); } 上面兩段黃色一樣的部分,可以只寫一次嗎? 若只寫一次要宣告在何處呢 是不是要寫在web.asax裡面呢? 謝謝高手指教 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.24.241.125
tomex:寫在web.config裏,再用System.Configurxxx.AppSettings[] 12/02 17:36
aming73:thank you 12/02 22:43