I have been reading about the lists in asp.net and how it works, I currently have a web application where I do a lot of queries to the database and therefore the performance is not the desired one.
I have done several exercises introducing the data to the lsita manually
example:
ClaimedVehicles MyVehicles = new ClaimedVehicles(1, "hola", DateTime.Today, "MyModel", 1, "asas", "asas");
ClaimedVehicles MyVehicles1 = new ClaimedVehicles(1, "hola", DateTime.Today, "P3", 1, "asas", "asas");
ClaimedVehicles MyVehicles2 = new ClaimedVehicles(2, "hola", DateTime.Today, "P3", 1, "asas", "asas");
List<ClaimedVehicles> MyListOFVehicles = new List<ClaimedVehicles>();
MyListOFVehicles.Add(MyVehicles);
MyListOFVehicles.Add(MyVehicles1);
MyListOFVehicles.Add(MyVehicles2);
MyListOFVehicles.Add(new ClaimedVehicles(1, "hola", DateTime.Today, "hi", 1, "asas", "asas"));
but I can not understand how I have to do with a database query.
I currently have a database in access, I've been trying to get the data from the table users
public class Users
{
public int ID { get; set; }
public String NAME { get; set; }
public int TEAM { get; set; }
public int ROL_ID { get; set; }
public Users(
int id,
String name,
int team,
int rol_id
)
{
this.ID = id;
this.NAME = name;
this.TEAM = team;
this.ROL_ID = rol_id;
}
private Users() { }
}
and on my list something like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.OleDb;
namespace ToolTrackSystem.List
{
public class ListUsers
{
String myConnectionString = @"C:\Users\gutiece\Desktop" + "tool_track.accdb";
static void Main(string[] args)
{
List<Data.Users> newUserList = new List<Data.Users>();
using (OleDbConnection connection = new OleDbConnection())
{
using (OleDbCommand command = new OleDbCommand())
{
try
{
string Query = @"SELECT id, who, payroll_number, name, ou, pool, team, rol_id FROM users ORDER BY id DESC AS Users";
OleDbCommand = Query; <-- no se que siga y me marca error
}
catch (Exception)
{
throw;
}
}
}
}
}
}
I want to have the data in a list and serialize it to an XML file to have a quicker reading of all the data ... my problem and question is that I do not know what to do for the query
How do I make the list with a realization of the query?