Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a Winform with SQlite database, I need to save the date from the DateTimPicker only if selected and cant figure it out. Currently it is saving whats in the dateTime picker.


C#
string txtQuery = "insert into Roster (Tech_Role, Employee, Picture, 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.Text + "','" + dateTimePicker7.Text +
              "','" + cb_TCAT.Text + "','" + cb_Fork.Text + "','" + cb_Tug.Text + "','"
              + dateTimePicker2.Text + "','" + dateTimePicker3.Text + "','" + dateTimePicker4.Text + "'" +
              ",'" + dateTimePicker5.Text + "','" + dateTimePicker6.Text + "','" + cb_Active.Text + "')";


What I have tried:

To many codes to list, and days of searching on the Net.
Posted
Updated 22-Apr-20 8:03am
v2
Comments
Richard MacCutchan 22-Apr-20 12:41pm    
Unless you show us the code that is not working, and explain exactly what is happening, it is impossible to help.
Member 12349103 22-Apr-20 13:32pm    
string txtQuery = "insert into Roster (Tech_Role, Employee, Picture, 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.Text + "','" + dateTimePicker7.Text +
"','" + cb_TCAT.Text + "','" + cb_Fork.Text + "','" + cb_Tug.Text + "','"
+ dateTimePicker2.Text + "','" + dateTimePicker3.Text + "','" + dateTimePicker4.Text + "'" +
",'" + dateTimePicker5.Text + "','" + dateTimePicker6.Text + "','" + cb_Active.Text + "')";
Patrice T 22-Apr-20 13:36pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
#realJSOP 23-Apr-20 10:54am    
dude, don't do it that way. Your code is vulnerable to sql injection attacks

As already stated, we can't give you specific help if you won't share your code. But...

0) If the data is "new", you should be setting the date to a reasonable default, so that saving it ifit's not selected isn't an issue.

1) The date should always be in a saveable state. Just because it didn't change, doesn't mean it's not valid.

2) If you insist on going down this path, you could create a bool variable that indicates when the user selects a new date, and set it to false when the form is instantiated, and react to one of the datepicker events to indicate that the user changed it. At that point, you can set your saving code to only save the date if your bool variable is true. Again, this is a BAD way to do it.
 
Share this answer
 
Comments
Member 12349103 22-Apr-20 17:36pm    
I have added my Save button when i enter text in the textbox and dont select the Datetime picker it saves the date.
#realJSOP 22-Apr-20 20:43pm    
Configure your Datepicker to force the user to actually select the dat with the picker.
Member 12349103 23-Apr-20 10:20am    
That's what I cant figure out.
Quote:
I have a Winform with SQlite database, I need to save the date from the DateTimPicker only if selected and cant figure it out. Currently it is saving whats in the dateTime picker.

advice: Stop combining simple problems to super problems.
Variables are the glue between the different parts of your app.
Your problem is either getting value from DateTimPicker to variable, either saving variable value to SQL.
Quote:
To many codes to list, and days of searching on the Net.

Common solution is to make a toy app which exhibit the problem, show minimized code should not be more than 20-30 lines of code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900