0

How to get the result of this SQLite query result in variable? I need to access this in my Windows 8.1 application.

string queryDB = string.Format("Select * from ContryLookup");
var tempcountryLookUpData = connection.Execute(queryDB);

Thanks

2 Answers 2

0

You will need reference to SqliteDataReader

static void Main() 
{
    string cs = "URI=file:test.db";

    using(SqliteConnection con = new SqliteConnection(cs))
    {
        con.Open();

        string stm = "Select * from ContryLookup";

        using (SqliteCommand cmd = new SqliteCommand(stm, con))
        {
            using (SqliteDataReader rdr = cmd.ExecuteReader())
            {
                while (rdr.Read()) 
                {
                    Console.WriteLine(rdr.GetInt32(0) + " " 
                        + rdr.GetString(1) + " " + rdr.GetInt32(2));
                }         
            }
        }

        con.Close();   
     }
}

Credits

Worth mentioning

Sign up to request clarification or add additional context in comments.

Comments

0

Do you have an execute procedure called Execute?? One way to do what you want is using the ExecuteReader procedure and return that to a DataReader object. Then use a for loop to traverse the data:

string sql = "select * from table";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
       Console.WriteLine(reader["columnName"]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.