SELECT Query Example
Command1 = new System.Data.SQLite.SQLiteCommand(Connection1);
Command1.CommandText = "SELECT * FROM MyTable WHERE SomeColumnName >= @StartValue AND SomeColumnName <= @EndValue";
Command1.Parameters.AddWithValue("@StartValue", 14);
Command1.Parameters.AddWithValue("@EndValue", 28);
System.Data.SQLite.SQLiteDataReader Reader1 = Command1.ExecuteReader();
{
while (Reader1.Read())
{
//MyVariable = Convert.ToString(Reader1["SomeColumnName1"]);
//MyVariable2 = Convert.ToInt32(Reader1["SomeColumnName2"]);
}
}
Reader1.Close();
Getting Count Of Rows Returned
//Get the number of results that will be returned
int RowCount = 0;
Command1 = new System.Data.SQLite.SQLiteCommand(Connection1);
Command1.CommandText = "SELECT count(*) FROM MyTable WHERE SomeColumnName >= @StartValue AND SomeColumnName <= @EndValue"; //The count() will return the number of results
RowCount = Convert.ToInt32(Command1.ExecuteScalar());
//Get the results
Command1.CommandText = "SELECT * FROM MyTable WHERE SomeColumnName >= @StartValue AND SomeColumnName <= @EndValue";
Command1.Parameters.AddWithValue("@StartValue", 14);
Command1.Parameters.AddWithValue("@EndValue", 28);
System.Data.SQLite.SQLiteDataReader Reader1 = Command1.ExecuteReader();
{
while (Reader1.Read())
{
//MyVariable = Convert.ToString(Reader1["SomeColumnName1"]);
//MyVariable2 = Convert.ToInt32(Reader1["SomeColumnName2"]);
}
}
Reader1.Close();
Reading DateTime In Select Statements
You need to specify you want the value returning in a DateTime format or you can just get the year portion returned!
Command1.CommandText = "SELECT datetime(LogDateTime) as LogDateTime, SomeOtherColumnName FROM MyTable";
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.