473,395 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 1952
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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...

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.