私はちょうどクライアントのリストを作成し、データベースからクライアントの詳細を取得し、それらをリストに追加してから、リストをDataGridに追加しました。ここに私のDataGridのXAMLコードです:余分な列を削除するにはどうすればよいですか?
<DataGrid x:Name="dataGridC" HorizontalAlignment="Left" Margin="10" VerticalAlignment="Top" Height="150" Width="1000" />
そして、これは私のコードビハインドである:私はすでにそれを試してみました
var cn = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\ASUS\Documents\Visual Studio 2015\Projects\G_D_C v2\G_D_C v2\G_D_C.mdb");
cn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "select * from [client]";
cmd.Connection = cn;
// OleDbDataReader rd = cmd.ExecuteReader();
using (OleDbDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
int ID = reader.GetInt32(0);
string nom_cs = reader.GetString(1);
int num_tel = reader.GetInt32(2);
int fax = reader.GetInt32(3);
string adresse = reader.GetString(4);
client c = new client(ID, nom_cs, num_tel, fax, adresse);
lsc.Add(c);
}
}
// dataGridC.ItemsSource = rd;
dataGridC.ItemsSource = lsc;