© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
6 replies
Hiccup

❔ Method WriteToTable(); isn't doing anything to the database file

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();
    }
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ [AllowedValue] not doing anything
C#CC# / help
2y ago
❔ Trouble doing anything with an SQLite database in ASP.NET
C#CC# / help
3y ago
Method on DI service doesn't do anything
C#CC# / help
2y ago
❔ The helper method 'Problem()' isn't in my controller scope. Pls help!
C#CC# / help
3y ago