Here is the code for the method that I am creating:
public void writeIt(string inputText, bool fasting)
{
var dbConnect = new SQLiteConnection("Data Source=database.sqlite;Version=3;");
dbConnect.Open();
using (SQLiteTransaction insertTrans = dbConnect.BeginTransaction())
{
using (SQLiteCommand insertCommand = new SQLiteCommand(dbConnect))
{
SQLiteParameter resultEntry = new SQLiteParameter();
insertCommand.CommandText = "INSERT INTO result(testResult, fasting) VALUES(@param1, @param2)";
insertCommand.Parameters.Add(new SQLiteParameter("@param1", System.Data.SqlDbType.VarChar).Value = inputText);
if(fasting)
{
insertCommand.Parameters.Add(new SQLiteParameter("@param2", System.Data.SqlDbType.Int).Value = "1");
}
else
{
insertCommand.Parameters.Add(new SQLiteParameter("@param2", System.Data.SqlDbType.Int).Value = "0");
}
insertCommand.ExecuteNonQuery();
}
insertTrans.Commit();
}
I am using the official sqlite database engine (if that matters). Currently the error that shows when I try to store data says the following
"Unable to cast object of type 'System.String' to type 'System.Data.SQLite.SQLiteParameter'" at the line "insertCommand.Parameters.Add(new SQLiteParameter("@param1", System.Data.SqlDbType.VarChar).Value = inputText);".
I openly(and freely) admit that I am not quite sure how to resolve this, as I am a novice and this is my second project of any significance.
Thank you for your kindness in advance.