üzerinde sql bu isteği var:
select * from table1 a,table2 b, table3 c where a.CodeA ='AB1234' and b.CodeB = 'AB1234' and c.CodeC='AB1234';
göster sql istek sonucu DataGridView
Ve DataGridView (C#) üzerindeki sonucunu göstermek istiyorum.
üzerinde sql bu isteği var:
select * from table1 a,table2 b, table3 c where a.CodeA ='AB1234' and b.CodeB = 'AB1234' and c.CodeC='AB1234';
göster sql istek sonucu DataGridView
Ve DataGridView (C#) üzerindeki sonucunu göstermek istiyorum.
Önce ardından bir liste olarak bu yönteme geçer sonuçlarınızı almak, size yardımcı olmak için bu kodu kullanabilirsiniz:
private void AddToDataGridView(List<yourClassName> Logs)
{
foreach (var item in Logs)
{
string[] row = new string[] { item.Id, item.Name, item.Description };
dataGridView.Rows.Add(row);
dataGridView.ClearSelection();
dataGridView.Rows[dataGridView.Rows.Count - 1].Selected = true;
dataGridView.FirstDisplayedScrollingRowIndex = dataGridView.Rows.Count - 1;
}
}
Not:string[] row = new string[] { item.Id, item.Name, item.Description };
bu düzen modellerine sizin DataGridView'ın sütun sırayla eşit olmalıdır duygusu. Örnek: Örnek:
Örnek.
AddToDataGridView(RepositoryName.GetResults());
: sizin gibi bu yöntemi çağırabilirsiniz formunuzda İçinde
public List<YourClassName> GetResults(string value1, string value2)
{
using (Command command = this.unitOfWork.Database.CreateCommand())
{
return command.ExecuteList<MiniLinhaSerialLog>(@"
SELECT * FROM table1 a,table2 b, table3 c
WHERE a.CodeA = 'AB1234'
AND b.CodeB = 'AB1234'
AND c.CodeC = 'AB1234'",
row => new YourResultClassName()
{
Id = row.Field<int>("Id"),
Name = row.Field<string>("Name"),
Description= row.Field<string>("Description"),
});
}
}