[問題] 如何在DataGrid上顯示資料庫的資料?
try
{
// step 1 . using System.Data.SqlClient;
// step 2 . 宣告連接字串
string Constr = @"Persist Security Info=true ; Integrated Security=true ; Initial Catalog=WPFDB ; Server=DL-TECH-41\SQLEXPRESS";
// step 3 . 建立SqlConnection
SqlConnection conn = new SqlConnection(Constr);
// step 4 . 宣告查詢字串
string Sqlstr = "select * from boss1";
// step 5. 建立SqlDataAdapter
SqlDataAdapter da = new SqlDataAdapter(Sqlstr, conn);
// step 6. 建立DataSet來儲存Table
DataSet ds = new DataSet();
// step 7. 將DataAdapter查詢之後的結果,填充至DataSet
da.Fill(ds);
// step 8 . 用DataGridView1 顯示出來
(目前卡在這邊) this.DataGrid = ds.Tables[0].DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
請問小弟該如何解?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.134.45.27
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1434440698.A.6E3.html
推
06/16 15:59, , 1F
06/16 15:59, 1F
→
06/16 16:14, , 2F
06/16 16:14, 2F
→
06/16 16:17, , 3F
06/16 16:17, 3F
→
06/16 16:23, , 4F
06/16 16:23, 4F
→
06/16 20:56, , 5F
06/16 20:56, 5F
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章