Hi gang ;
The code below works fine but a more flexible one would be better.
For example what am looking for an original try-throw-cath block which throws the exception "Item not found" message itself.
try {
SQLiteConnection ^connection = gcnew SQLiteConnection();
connection->ConnectionString = "Data Source = atbdn3.db3";
connection->Open();
System::String ^selecteditem = (textBox1->Text)->ToString();
SQLiteCommand^ command = connection->CreateCommand();
command->CommandText ="select energy from table where product ='"+selecteditem +"'" ;
SQLiteDataReader ^dataReader = command->ExecuteReader();
if (dataReader->HasRows == true)
{
while (dataReader->Read())
{
label1->Text = dataReader["energy_kcal"]->ToString();
}
}
else
{
MessageBox::Show("ITEM NOT FOUND."); // SQLite error imitation !
}
connection->Close();
}
catch(Exception ^e ) {
MessageBox::Show(e->Message) ; // SQLite error : no such table
}