I am wondering if the following code is an old approach for working with database. Or I can use more modern and productive approach?
using(SqlConnection con = new SqlConnection(Properties.Settings.Default.EventLogPrinterConnectionString))
{
SqlCommand com = new SqlCommand("", con);
string sql_com_sel = "";
sql_com_sel = @"SELECT DISTINCT Users, Pages, Date FROM View_lastactiveUser WHERE (Date >= @ds AND Date <= @dp AND Pages > 0) ORDER BY Date";
com.CommandText = sql_com_sel;
com.Parameters.Clear();
com.Parameters.Add("@ds", SqlDbType.DateTime).Value = ds;
com.Parameters.Add("@dp", SqlDbType.DateTime).Value = dp;
con.Open();
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
users.Add(new UserDemo() { LastActivity = dr["Date"].ToString(), Pages = int.Parse(dr["Pages"].ToString()), User = dr["Users"].ToString() });
}
con.Close();
return users;
}
you could use LinqtoSQL or The ADO.NET Entity Framework Overview
There are also some other solutions like nHibernate, but the first to come nativly with .NET