我目前正在編寫一個WinForms應用程序,我想使用DataGridView
。我知道如何DataGridView
與表綁定數據庫這樣的:將定製的DataGridView與SQL Server數據庫綁定
using (SqlConnection con = new SqlConnection(WF_AbsPres.Properties.Settings.Default.DbConnectionString))
{
SqlDataAdapter a = new SqlDataAdapter("SELECT * FROM DevInOut", con);
SqlCommandBuilder comdBuilder = new SqlCommandBuilder(a);
DataTable t = new DataTable();
//t.Locale = System.Globalization.CultureInfo.InvariantCulture;
a.Fill(t);
//dataGridView1.AutoGenerateColumns = false;
bindingSource1.DataSource = t;
/// bind the grid view with binding source
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
dataGridView1.ReadOnly = true;
dataGridView1.DataSource = bindingSource1;
dataGridView1.DataSource = t;
con.Close();
}
但事實是這樣的dataGridView
顯示錶的所有列。我想在dataGridView中手動添加列,並將每個列綁定到數據庫表中的特定列。這意味着我不想顯示一些列。
我該怎麼做?由於
'你知道SELECT *'是什麼意思..?你正在選擇所有的列.. – MethodMan
需要了解basci SQL以及需要顯示更多的努力 我敢打賭,如果你看看'Related'鏈接到這個頁面的右邊,你可以找到答案.. SHOW SOME努力 – MethodMan
阿哈你是對的,謝謝。一個問題:我在數據庫中的表有這樣的字段:ID,時間,日期,但我希望網格視圖中的標題以另一種語言顯示,例如farsi。我怎樣才能做到這一點? – user2628363