看板 C_Sharp 關於我們 聯絡資訊
大家好 小弟第一次在此發文 有些問題想請教一下 謝謝 像我是想要按一個button後 便可以載入此資料表的資料 show在gridview上 以下是我的程式碼 protected void Button3_Click(object sender, EventArgs e) { conn.Open(); SqlCommand cmd = conn.CreateCommand() ; cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM D"; cmd.ExecuteNonQuery(); DataTable dt = new DataTable(); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(dt); GridView1.DataSource = dt; conn.Close(); } 我參考過很多資料了 我也覺得這樣應該按下button後 可以show出我資料表的所有資料在gridview裡面 但按下button後完全沒有反應 請問 我是不是哪裡出了問題 我的環境是VS2010 我是用SQL server management studio 來建立我的資料庫以及資料表 謝謝 如果有其他東西我沒附上的 麻煩告知我一下 謝謝 希望可以早日解決 卡很久了>< -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.27.95.31 ※ 文章網址: http://www.ptt.cc/bbs/C_Sharp/M.1409844328.A.5FC.html
O187: 你確定datatable內有資料嗎? 09/04 23:31
ya12590: 有的!! 我確定 09/04 23:32
GoalBased: 沒bind 阿 09/05 07:50
GoalBased: GridView1.DataSource = dt; 09/05 08:30
GoalBased: 後面一行 09/05 08:31
GoalBased: GridView1.DataBind() 09/05 08:31
jcpf126: 推樓上,另外建議你研究SqlDataAdapter,可以寫得更簡潔 09/05 09:07
ya12590: 謝謝各位馬上試 09/05 10:31