SELECT Query Example


	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();
	//Bugfix to workaround sqlite "database is locked" issue when updating after a read
	while (!Reader1->IsClosed)
		System::Threading::Thread::Sleep(1);		//mS

 

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.

Comments

Your email address will not be published. Required fields are marked *