Every time I get something from the db, my code is this:
using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.v3ConnString))
{
conn.Open();
using (SqlCommand command = new SqlCommand())
{
command.Connection = conn;
command.CommandText = "SELECT ...";
command.Parameters.AddWithValue("...", ...);
using (SqlDataReader dr = command.ExecuteReader())
{
if (dr.HasRows)
someVar = true;
}
}
}
Instead I want to do myArray = Db.sql("SELECT ...") or something else if there is a better way. Can somebody point me in the right direction?
EDIT: I’m not looking for code to generate SQL for me, rather an easy way of getting an array result from an SQL query.
Checkout Dapper.NET. It’s a lightweight ORM which will simplify this task.