How to retrieve data from Database by ( List<> ) instead of data table?
如何通过(List <>)而不是数据表从数据库中检索数据?
How can I do this?
我怎样才能做到这一点?
1 个解决方案
#1
0
Follow these steps
按着这些次序
- create a class emulating your table
- declare the list
- retrieve data and bind it to the list
-
display your data
显示您的数据
public class myListClass { public string myListClassItem1{ set; get; } public string myListClassItem2{ set; get; } public string myListClassItem3{ set; get; } }
public class myListClass {public string myListClassItem1 {set;得到; public string myListClassItem2 {set;得到; public string myListClassItem3 {set;得到; }}
List items = new List();
List items = new List();
while (reader.Read()) { items.Add(new myListClass(reader["Item1"].ToString(), reader["Item2"].ToString(), reader["Item3"].ToString())); }
while(reader.Read()){items.Add(new myListClass(reader [“Item1”]。ToString(),reader [“Item2”]。ToString(),reader [“Item3”]。ToString())) ; }
myDataGrid.DataSource = items;
myDataGrid.DataSource = items;
myDataGrid.DataBind();
创建一个模拟表格的类
声明清单
检索数据并将其绑定到列表
#1
0
Follow these steps
按着这些次序
- create a class emulating your table
- declare the list
- retrieve data and bind it to the list
-
display your data
显示您的数据
public class myListClass { public string myListClassItem1{ set; get; } public string myListClassItem2{ set; get; } public string myListClassItem3{ set; get; } }
public class myListClass {public string myListClassItem1 {set;得到; public string myListClassItem2 {set;得到; public string myListClassItem3 {set;得到; }}
List items = new List();
List items = new List();
while (reader.Read()) { items.Add(new myListClass(reader["Item1"].ToString(), reader["Item2"].ToString(), reader["Item3"].ToString())); }
while(reader.Read()){items.Add(new myListClass(reader [“Item1”]。ToString(),reader [“Item2”]。ToString(),reader [“Item3”]。ToString())) ; }
myDataGrid.DataSource = items;
myDataGrid.DataSource = items;
myDataGrid.DataBind();
创建一个模拟表格的类
声明清单
检索数据并将其绑定到列表