I'm trying to have a generic function for SQL queries with the output being a datareader. I'm getting a database locked error when running my code though, so I put a dbconn.close before my return but then I get an error saying the connection is closed and so the data no longer is in the reader to return. Catch 22. I think I must be going about this the wrong way. Can anyone point me in the direction of tutorials that don't use scalar and are relevant to C#.net? Or at least, could someone suggest a different method for doing this:
public static SQLiteDataReader ExecuteQuery(string strSql)
{
SQLiteConnection dbConn = new SQLiteConnection("Data Source=" + dbPath + @"\" + dbName);
dbConn.Open();
SQLiteCommand sqlQ = new SQLiteCommand(dbConn);
sqlQ.CommandText = strSql;
SQLiteDataReader sqlReader = sqlQ.ExecuteReader();
dbConn.Close();
return sqlReader;
}
SQLiteDataReader sqlReader;
sqlReader = SQL.ExecuteQuery("SELECT count(FilePath) FROM files WHERE FilePath = '" + strSPath + "';");