Вот код: Код | 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"); } } }
|
Выбрасывает ошибку во время вставки данных в базу данных SQLite. Ошибка указывает на это: Вроде все верно... В чем ошибка?
|