I have a problem, need to get data (string) from textboxes and add to the new string of the table, but my code causes an exception:
SQL logic error or missing database
no such table: NoteTestTable2
Code:
public partial class MainWindow : Window
{
string dbConnectionString = @"Data Source=NoteTest.sqlite;Version=3;";//Создаем соединение с нашей базой данных "NoteTest"
public MainWindow()
{
InitializeComponent();
}
private void NameTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void SaveData_Click(object sender, RoutedEventArgs e)
{
SQLiteConnection sqliteCon = new SQLiteConnection(dbConnectionString);
try
{
sqliteCon.Open();//Открываем соединение с бд
string Query = "INSERT INTO NoteTestTable2 (Name,LastName) VALUES('" + this.NameTextBox.Text + "' , '" + this.LastNameTextBox.Text + "' )";//Создаем наш запрос SQL и помещаем его в переменную Query
SQLiteCommand CreateCommand = new SQLiteCommand(Query, sqliteCon);
CreateCommand.ExecuteNonQuery();
SQLiteDataReader dr = CreateCommand.ExecuteReader();
MessageBox.Show("Запись внесена!");
sqliteCon.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
 
Aucun commentaire:
Enregistrer un commentaire