Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# sqlite query

public List<string> GetUsers()
{
	// Init return list
    List<string> users = new List<string>();

	// Set the path to sqlite file
    string solutionPath = Environment.CurrentDirectory;
	string dbPath = Path.Combine(solutionPath, "db.sqlite3");    

    SQLiteConnection connection = new SQLiteConnection(solutionPath);
    connect.Open();

	// Construct sql query
    SQLiteCommand command = connection.CreateCommand();
    command.CommandText = @"SELECT username FROM tableUsers";
    command.CommandType = CommandType.Text;

    SQLiteDataReader reader = command.ExecuteReader();

	// reader is treated like a array so call 
    while (reader.Read())
    	users.Add(Convert.ToString(reader["username"]));

	// Clean up no longer needed connection
	connection.Close();

    return users;
}
 
PREVIOUS NEXT
Tagged: #sqlite #query
ADD COMMENT
Topic
Name
3+4 =