0
我有一個datagridview,我想用LINQ查詢加載它的數據。當我調試我可以看到數據源有正確的數據和查詢,但他們不出現在dgv中,它完全是空的,沒有行沒有列。我查了很多已經問過的問題,但無法解決。它的Windows窗體應用程序順便說一句。我也有另一個linq查詢插入一些數據,它工作正常,所以我假設問題不是關於linqtosql類。c#linqtosql datagridview完全爲空
namespace StokUygulamasi
[Database(Name = "HarleyDavidson")]
class HarleyDavidson : DataContext
{
public HarleyDavidson() : base("Data Source=SELCUK-CODE\\LOCALHOST;Initial Catalog = HarleyDavidson; Integrated Security = true")
{
}
public HarleyDavidson(SqlConnection con) : base(con) { }
public Table<Motor> Motor
{
get
{
return this.GetTable<Motor>();
}
}
public Table<IkinciEl> IkinciEl
{
get
{
return this.GetTable<IkinciEl>();
}
}
public Table<Musteri> Musteri
{
get
{
return this.GetTable<Musteri>();
}
}
public Table<Satis> Satis
{
get
{
return this.GetTable<Satis>();
}
}
}
[Table(Name = "Motor")]
public class Motor
{
[Column(Storage = "MotorID", DbType ="Int Not null", IsPrimaryKey = true, IsDbGenerated = true)]
public int MotorID;
[Column(Storage = "Marka", DbType = "nvarchar(20) Not null")]
public string Marka;
[Column(Storage = "Model", DbType = "nvarchar(20) Not null")]
public string Model;
[Column(Storage = "Seri", DbType = "nvarchar(20) Not null")]
public string Seri;
[Column(Storage = "Plaka", DbType = "nvarchar(20) Not null")]
public string Plaka;
[Column(Storage = "Sasi", DbType = "char(17) Not null")]
public string Sasi;
[Column(Storage = "KM", DbType = "int Not null")]
public int KM;
[Column(Storage = "Yil", DbType = "int Not null")]
public int Yil;
[Column(Storage = "AlisFiyat", DbType = "decimal(18,2) Not null")]
public decimal AlisFiyat;
[Column(Storage = "SatisFiyat", DbType = "decimal(18,2) Not null")]
public decimal SatisFiyat;
}
[Table(Name = "Musteri")]
public class Musteri
{
[Column(Storage = "MusteriID", DbType = "Int Not null", IsPrimaryKey = true, IsDbGenerated = true)]
public int MusteriID;
[Column(Name = "Ad", DbType = "nvarchar(100) Not null")]
public string Ad;
}
[Table(Name = "Satis")]
public class Satis
{
[Column(Name = "SatisID", DbType = "Int Not null", IsPrimaryKey = true, IsDbGenerated = true)]
public int SatisID;
[Column(Name = "Tarih", DbType = "Date Not null")]
public DateTime Tarih;
[Column(Name = "Musteri", DbType = "nvarchar(100) Not null")]
public string Musteri;
[Column(Name = "Arac", DbType = "nvarchar(10) Not null")]
public string Arac;
[Column(Name = "AracSasi", DbType = "char(17) Not null")]
public string AracSasi;
[Column(Name = "Tutar", DbType = "decimal(18,2) Not null")]
public decimal Tutar;
}
[Table(Name = "IkinciEl")]
public class IkinciEl
{
[Column(Name = "IkinciElID", DbType = "int Not null", IsPrimaryKey = true, IsDbGenerated = true)]
public int IkinciElID;
[Column(Name = "Marka", DbType = "nvarchar(20) Not null")]
public string Marka;
[Column(Name = "Model", DbType = "nvarchar(20) Not null")]
public string Model;
[Column(Name = "Seri", DbType = "nvarchar(20) Not null")]
public string Seri;
[Column(Name = "Plaka", DbType = "nvarchar(10) Not null")]
public string Plaka;
[Column(Name = "Sasi", DbType = "char(17) Not null")]
public string Sasi;
[Column(Name = "KM", DbType = "int Not null")]
public int KM;
[Column(Name = "Yil", DbType = "int Not null")]
public int Yil;
[Column(Name = "Fiyat", DbType = "decimal(18,2) Not null")]
public decimal Fiyat;
}
private void Form1_Load(object sender, EventArgs e)
{
hdc = new HarleyDavidson(con);
var sonuc = from a in hdc.IkinciEl select a;
dgvIkinciEl.DataSource = sonuc.ToList();
//var bindingSource = new BindingSource();
//bindingSource.DataSource = sonuc.ToList();
//dgvIkinciEl.DataSource = bindingSource;
}
this.dgvIkinciEl.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvIkinciEl.Location = new System.Drawing.Point(3, 3);
this.dgvIkinciEl.Name = "dgvIkinciEl";
this.dgvIkinciEl.Size = new System.Drawing.Size(648, 247);
this.dgvIkinciEl.TabIndex = 0;