Option 1
Take a look at dapper-dot-net which is a micro ORM that would allow you to convert your queries to objects. You can put these in a data access layer and if you need a full blown ORM later like entity framework it would be easy to move it.
http://code.google.com/p/dapper-dot-net/
There's also massive by Rob Connery https://github.com/robconery/massive
If you're running bigger queries that may be a sign that you need a full blown ORM.
Option 2
Use a parameterized query. You can write you SQL to take parameters. You can store .sql files, or you can have an xml file that contains your queries. Your queries would contain the parameters:
I would imagine your xml would look something like so:
<?xml version="1.0" encoding="UTF-8" ?>
<sql-queries>
<statement>
<id>get-id</id>
<sql>SELECT UserId FROM User WHERE UserName = @UserName AND Password = @Password;</sql>
</statement>
</sql-queries>
After loading your query (either from reading a text or reading an XML file). You can execute using parameters.
using (SqlCommand cmd = new SqlCommand(sql))
{
// Create the parameter objects as specific as possible.
cmd.Parameters.Add("@UserName", System.Data.SqlDbType.NVarChar, 50);
cmd.Parameters.Add("@Password", System.Data.SqlDbType.NVarChar, 25);
// Add the parameter values. Validation should have already happened.
cmd.Parameters["@UserName"].Value = UserName;
cmd.Parameters["@Password"].Value = Password;
cmd.Connection = connnection;
try
{
cmd.Connection.Open();
var userId = cmd.ExecuteScalar();
}
catch (SqlException sx)
{
// Handle exceptions before moving on.
}
}
Code from: http://software-security.sans.org/developer-how-to/fix-sql-injection-microsoft-.net-with-parameterized-queries
One thing I would definitely do in this case is encrypt the XML so that users can't modify it, but that will be up to you to do that. You can check out this link on doing so Encrypt and decrypt a string