473,463 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

update datetimepicker

64
Hi, can anyone help me to guide on how to update using datetimepicker?

Here is my sql syntax :-
Expand|Select|Wrap|Line Numbers
  1. UPDATE table set Date='" + datetimepicker1.Text + "' WHERE ID='" + ID.Text + "';
After I run the message prompat said Syntax Missing..

ASAP me if got solution
Oct 14 '15 #1
2 1956
1. Add a timer to your form.

2. Set timer interval to 1000 (milliseconds)

3. Set Enabled property to True

4. Update the DateTimePicker value in the Tick event of the timer as below


Expand|Select|Wrap|Line Numbers
  1.  private void timer1_Tick(object sender, EventArgs e)
  2.         {
  3.             dateTimePicker1.Value = DateTime.Now; 
  4.         }
Oct 16 '15 #2
adriancs
122 100+
I assumed that the value of dateTimePicker1.Value is something like this (MM-dd-yyyy):

Expand|Select|Wrap|Line Numbers
  1. 12-23-2015
Then you can get the datetime value like this

Expand|Select|Wrap|Line Numbers
  1. string[] sa = dateTimePicker1.Value.Split('-');
  2. int month = Convert.ToInt(sa[0]);
  3. int day = Convert.ToInt(sa[1]);
  4. int year = Convert.ToInt(sa[2]);
  5. DateTime dateTime1 = new DateTime(year, month, day);
  6. string datestr = dateTime1.ToString("yyyy-MM-dd HH:mm:ss");
  7. int id = Convert.ToInt(ID.Text);
  8.  
  9. string sql = string.Format("UPDATE table set `Date`='{0}' WHERE ID={1};",
  10. datestr, id);
  11.  
Dec 23 '15 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
2
by: LC | last post by:
I am on the learn C#. Net in 695 day program. I am just trying to learn stuff. I have MSAccess database with 1 table called 'ParmDate' with 1 column called 'ParmDate' which represents a date for...
4
by: Jacek Jurkowski | last post by:
.... the minimum date of DateTimePicker is 1753-01-01. How to make DateTime to do not show nothing in its text if this date is the value? I have a form with a field LastLogonDate. If user hasn't...
11
by: Manuel Canas | last post by:
Hi There, I have this problem I'm trying to address but no luck so far, need your help here. How do I set the value of a DateTimePicker Programmatically? When I do this: txtDate.Value =...
2
by: Chris Fairman | last post by:
NG, Maybe I'm missing a key step, but it seems when typing dates into a DateTimePicker control (format = 'Short'), the controls' .text property is not updated until the control losses focus. ...
7
by: Clamara | last post by:
When adding a new record from my form, I pre-set my DateTimePicker's value to System.DateTime.Today Since the "Today" value is used most of the time, the user doesn't need to select a date from...
3
by: Charlie | last post by:
In the top portion of the DateTimePicker, where the value of the date is displayed, how can I detect whether the month or day or year is currently focused, or, if ShowCheckBox = True, whether the...
5
by: Alpha | last post by:
I have a DateTimePicker control that originally displays "1/1/1900" on screen. I want to change it to current date when a user clicks on it. I use the follow code but nothing is happening. Can...
3
by: oceantrain | last post by:
I have a datagridview with 10 columns. Every month the user will update new info in the grid. I would like to have a datetimepicker next to the binding navigator. The purpose of the datetimepicker is...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.