嘿傢伙,我有一個應用程序,我想顯示一些數據從DataGridView中的一個SQL數據庫...我現在在DataGridView中顯示的數據,但這裏是我的問題...如何可以我使用自定義標題標題,因爲我不希望將SQL列標題用於DataGridView列標題。另外,我希望它能夠在用戶雙擊一行時打開該行的filePath值...我也希望能夠指定列的寬度。這是如何放置表格。DataGridView中的SQL數據
SQL表: ROW_ID(我不想顯示網格),部分號碼,CMMNumber,CreatedOn,文件路徑,RacfId,currTime
數據網格視圖中所需的格式: 型號,CMM號碼,創建時間,路徑,用戶ID,在
當前代碼 - 它獲取數據(包括Row_ID),並使用sql列名作爲數據網格視圖列的名稱,它也只使用默認列寬。
private void NewAlert_Load(object sender, EventArgs e)
{
string connString = "Server=FRXSQLDEV;Database=MyDB;User Id=ID;Password=Password;";
string query = "SELECT * FROM CMMReports WHERE RacfId IS NULL;";
SqlDataAdapter dAdapter = new SqlDataAdapter(query, connString);
SqlCommandBuilder cBuilder = new SqlCommandBuilder(dAdapter);
DataTable dTable = new DataTable();
dAdapter.Fill(dTable);
//BindingSource to sync DataTable and DataGridView
BindingSource bSource = new BindingSource();
//set the BindingSource DataSource
bSource.DataSource = dTable;
//set the DataGridView DataSource
dgView.DataSource = bSource;
dAdapter.Update(dTable);
}
你可以閱讀的DataGridView常見問題這對我幫助很大http://www.google.co.nz/url?sa=t&source=web&ct=res&cd=1&ved=0CAYQFjAA&url=http %3A%2F%2Fwww.windowsclient.net%2FSamples%2FGo%2520To%2520Market%2FDataGridView%2FDataGridView%2520FAQ.doc&rct = j&q = datagridview + faq&ei = bNrpS8vCMoqOkQXkxcCHCw&usg = AFQjCNEnheLFyYG0nwJGotD8HjYYZl8Rug – adopilot 2010-07-02 06:55:43