I keep getting this error every time I try to add something into the database. I am trying to add something into a database that's already in the executable.
This is how I am trying to add it:
public class DBAccess
{
public static void AddTransaction(Transaction transaction)
{
using IDbConnection dbConnection = new SQLiteConnection(LoadConnection());
dbConnection.Execute("INSERT INTO Transaction (Category, Name, Type, Date, Amount, Method, Description, Recurring" +
") VALUES (@Category, @Name, @Type, @Date, @Amount, @Method, @Description, @Recurring)", transaction);
}
public static string LoadConnection(string conn = "Connection")
{
return ConfigurationManager.ConnectionStrings[conn].ConnectionString;
}
}
This is the model:
public class Transaction
{
public int TransactionID { get; set; }
public string Category { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public string Date { get; set; }
public int Amount { get; set; }
public string Method { get; set; }
public string Description { get; set; }
public string Recurring { get; set; }
}
This is what I am trying to add:
class Program
{
static void Main(string[] args)
{
Transaction transaction = new Transaction();
Console.WriteLine("Category: ");
transaction.Category = Console.ReadLine();
Console.WriteLine("Name: ");
transaction.Name = Console.ReadLine();
Console.WriteLine("Type: ");
transaction.Type = Console.ReadLine();
Console.WriteLine("Date: ");
transaction.Date = Console.ReadLine();
Console.WriteLine("Amount: ");
bool isAmountConverted = int.TryParse(Console.ReadLine(), out int amount);
if (isAmountConverted)
{
transaction.Amount = amount;
}
Console.WriteLine("Method: ");
transaction.Method = Console.ReadLine();
Console.WriteLine("Description: ");
transaction.Description = Console.ReadLine();
Console.WriteLine("Recurring: ");
transaction.Recurring = Console.ReadLine();
DBAccess.AddTransaction(transaction);
}
}
This is the database:
