SQLite only save date from DatetimePicker if selected

  • Thread starter Thread starter Booney440
  • Start date Start date
B

Booney440

Guest
I have a Winform with SQlite database, i need to save the date from the DateTimPicker only if selected and cant figure it out.

Any help please.

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

Refresh();
this.dataGridView1.RowsDefaultCellStyle.BackColor = System.Drawing.Color.Bisque; // datagrid color
this.dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.Color.Beige; // datagrid color

dataGridView1.AutoResizeColumns();
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

}

private int i = 0;

private SQLiteConnection sql_con;
private SQLiteCommand sql_cmd;
private SQLiteDataAdapter DB;
private DataSet DS = new DataSet();
private DataTable DT = new DataTable();

private void Form1_Load(object sender, EventArgs e)
{
LoadData();


}

//Set Connection
private void SetConnection()
{
sql_con = new SQLiteConnection
("Data Source=MH_Roster.db;Version=3;new=False;Compress=True;");

}

//set executequery
private void ExcuteQuery(string txtQuery)
{
SetConnection();
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
sql_cmd.CommandText = txtQuery;
sql_cmd.ExecuteNonQuery();
sql_con.Close();

}

//set loadDB
private void LoadData()
{
SetConnection();
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
string CommandText = "select * from Roster";
DB = new SQLiteDataAdapter(CommandText, sql_con);
DS.Reset();
DB.Fill(DS);
DT = DS.Tables[0];
dataGridView1.DataSource = DT;
sql_con.Close();
}

#region Buttons

private void btn_New_Click(object sender, EventArgs e)
{

}

private void btn_Save_Click(object sender, EventArgs e)
{
string txtQuery = "insert into Roster (Tech_Role, Picture, Employee, Employee_Number, Shift, Zone, Supervisor, On_Board_Date_into_Material_Handling," +
"Basic_Skills, TCAT_Certifaction, Basic_Skills_Fork_Pass, Basic_Skills_Tug_Pass, Regional_Training, Job_Observation_Training, Advance_Training, Previous_Safety_Training," +
"Current_Safety_Training, MH_Employee_Active )values('"
+ cb_Role.Text + "', '" + tb_Name.Text + "', '" + pictureBox1.Text + "', '" + tb_Employee_Number.Text + "', '" + cb_Shift.Text + "', '" + tb_Zone.Text + "', '" + tb_Supervisor.Text + "','"+ dateTimePicker1.Value + "','" + dateTimePicker7.Value + "','" + cb_TCAT.Text + "','" + cb_Fork.Text + "','" + cb_Tug.Text + "','" + dateTimePicker2.Value + "','" + dateTimePicker3.Value + "','" + dateTimePicker4.Value + "','" + dateTimePicker5.Value + "','" + dateTimePicker6.Value + "','" + cb_Active.Text + "')";



ExcuteQuery(txtQuery);
LoadData();

}








Booney440

Continue reading...
 
Back
Top