DataTable'ı nasıl alabilirim ve bir listeye nasıl dönüştürürüm?DataTable Liste <object>
Hem C# hem de VB.NET'te aşağıdaki kodları ekledim, her ikisi de sorunu, verileri döndürmek için yeni bir nesne oluşturmamızdır, ki bu çok maliyetlidir. Nesneye bir başvuru göndermem gerekiyor.
DataSetNoteProcsTableAdapters.up_GetNoteRow nesnesi INote arabirimini uygular. .NET 3.5
C# kodu ile
public static IList<INote> GetNotes()
{
DataSetNoteProcsTableAdapters.up_GetNoteTableAdapter adapter =
new DataSetNoteProcsTableAdapters.up_GetNoteTableAdapter();
DataSetNoteProcs.up_GetNoteDataTable table =
new DataSetNoteProcs.up_GetNoteDataTable();
IList<INote> notes = new List<INote>();
adapter.Connection = DataAccess.ConnectionSettings.Connection;
adapter.Fill(table);
foreach (DataSetNoteProcs.up_GetNoteRow t in table) {
notes.Add((INote)t);
}
return notes;
}
VB.NET Kod listesinin özellikleri alan adlarını
Public Shared Function GetNotes() As IList(Of INote)
Dim adapter As New DataSetNoteProcsTableAdapters.up_GetNoteTableAdapter
Dim table As New DataSetNoteProcs.up_GetNoteDataTable
Dim notes As IList(Of INote) = New List(Of INote)
adapter.Connection = DataAccess.ConnectionSettings.Connection
adapter.Fill(table)
For Each t As DataSetNoteProcs.up_GetNoteRow In table
notes.Add(CType(t, INote))
Next
Return notes
End Function
bir sebebi var? –
Dup: http://stackoverflow.com/questions/545328/datatable-to-generic-list-memory-leak/545429#545429 –
Müşteri genellikle LINQ2SQL veya LINQ kullanmak istemez. Bağlantı için teşekkürler, çok yardımcı olacaktır. Bazı zamanlar koşacağım ve ne olduğunu göreceğim – Coppermill