Here is the code:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SQLite; namespace WorkSQLite { public partial class Form1 : Form { Data_Connection db_object = new Data_Connection(); SQLiteConnection SQLiteConnect = new SQLiteConnection(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { SQLiteConnect.ConnectionString = db_object.datalocation(); SQLiteConnect.Open(); } private void button1_Click(object sender, EventArgs e) { SQLiteCommand SQLCommand = new SQLiteCommand(); SQLCommand = SQLiteConnect.CreateCommand(); SQLCommand.CommandText = "CREATE TABLE IF NOT EXISTS " + textBox1.Text + "( Username TEXT, Password TEXT);"; SQLCommand.ExecuteNonQuery(); SQLCommand.Dispose(); MessageBox.Show("Table Created"); } private void button3_Click(object sender, EventArgs e) { SQLiteCommand cmd = new SQLiteCommand(); cmd = SQLiteConnect.CreateCommand(); cmd.CommandText = "insert into " + textBox1.Text + " (Username,Password)  values (@username,@password)"; cmd.Parameters.AddWithValue("@username", textBox2.Text); cmd.Parameters.AddWithValue("@password", textBox3.Text); cmd.ExecuteNonQuery(); cmd.Dispose(); MessageBox.Show("Data Inserted"); } private void button2_Click(object sender, EventArgs e) { SQLiteCommand cmd = new SQLiteCommand("select * from " + textBox1.Text, SQLiteConnect); SQLiteDataAdapter da = new SQLiteDataAdapter(); DataTable dt = new DataTable(); da.SelectCommand = cmd; da.Fill(dt); if (dt.Rows.Count > 0) { dataGridView1.DataSource = dt; } else { MessageBox.Show("No Data Exist in Table"); } } } 

}

Throws an error while inserting data into a SQLite database. Error indicates this:

 cmd.ExecuteNonQuery(); 

It seems to be right ... What is the error?

I attach a screenshot of the error window

  • 2
    You looked at the debug what the final view takes your query after substituting textBox1.Text? - null
  • send at least an exception, otherwise a crystal ball will not even help - Senior Pomidor

0