My code:
private void button1_Click(object sender, EventArgs e)
{
WriteToTable();
}
public void WriteToTable()
{
string DBpath = @"Data Source=.\StudentInfoDB.db;Version=3;";
using SQLiteConnection SQLConnection = new SQLiteConnection(DBpath);
using var cmd = new SQLiteCommand(DBpath, SQLConnection);
SQLConnection.Open();
cmd.CommandText = "INSERT INTO Students (Name) VALUES ('Test')";
cmd.ExecuteNonQuery();
SQLConnection.Close();
}
In my database file, I have one table called Students and 3 columns called name, grade and phone number. I'm trying to ensure I correctly connected to the database so I decided I should try adding text under the Name column before I add anymore code.
I expected this code to output "Text" under the "Name" column to my database file, however after I press button1 nothing happens. No errors show up and no crashes occur.
I have tried debugging the code and searching online for common mistakes but sadly it did not help