TimonYang
Thanks a lot for sharing this piece of code.
I tried to modify it to my needs but it gives an error that there is no line in position 0.
using (SQLiteConnection connection = new SQLiteConnection(@"Data Source=Injection_Settings.db"))
{
connection.Open();
string selectSql = "CREATE TABLE IF NOT EXISTS Description (Mould_Code INTEGER NOT NULL PRIMARY KEY,Supplier TEXT NOT NULL,Colour TEXT NOT NULL,Machine_Type TEXT NOT NULL,Plastic_Type_1 TEXT,Plastic_Type_2 TEXT,Plastic_Type_3 TEXT,Machine_Number INTEGER NOT NULL,Date_Time TEXT NOT NULL);";
using (SQLiteCommand command = new SQLiteCommand(selectSql, connection))
{
dataTable = new DataTable();
dataTable.Load(command.ExecuteReader());
DataRow dataRow = dataTable.Rows[0];
}
}
private void Save_Click(object sender, EventArgs e)
{
using (SQLiteConnection connection = new SQLiteConnection(@"Data Source=Injection_Settings.db"))
{
connection.Open();
using (SQLiteDataAdapter sQLiteDataAdapter = new SQLiteDataAdapter(@"SELECT * FROM Description", connection))
{
SQLiteCommandBuilder commandBuilder = new SQLiteCommandBuilder(sQLiteDataAdapter);
sQLiteDataAdapter.Update(dataTable);
}
}
}
private void AddToDatatable_Click(object sender, EventArgs e)
{
DataRow dataRow = dataTable.NewRow();
dataRow["Mould_Code"] = mould_code_input.Text;
dataRow["Supplier"] = supplier_input.Text;
dataRow["Colour"] = colour_input.Text;
dataRow["Machine_Type"] = machine_type_input.Text;
dataRow["Plastic_Type_1"] = listBox1.Text;
dataRow["Plastic_Type_2"] = listBox4.Text;
dataRow["Plastic_Type_3"] = listBox6.Text;
dataRow["Machine_Number"] = machine_number_input.Text;
dataRow["Date_Time"] = dateTimePicker1.Text;
dataTable.Rows.Add(dataRow);
}