我如何摆脱额外的列?

时间:2017-05-07 16:22:49

标签: c# wpf datagrid

我刚刚创建了一个客户列表,从数据库中获取了客户端详细信息,将它们添加到列表中,然后将列表添加到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;

ScreenShot

0 个答案:

没有答案