Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
hi,
i am creating an application in c# in window gui and in that i have a date time picker i want know how the value of date time picker is stored in database table in which i have a coloumn name date of 'datetime' format
Posted 14-Jul-11 1:30am
Edited 14-Jul-11 1:35am
Prerak Patel140.1K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You seriously need to learn basic things.
Simple ADO.NET Database Read, Insert, Update and Delete using C#.[^]
 
"Insert into table (id, mytime) values(5, '" + myDTP.value.ToString("dd-MMM-yyyy HH:mm:ss") + "')"
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can convert the datetime to the database format either on the C# or on the SQL server side.
 
For C#, use DateTime functions to convert to appropriate format.
For SQL Server, use the CONVERT function[^].
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

 
'Try this its very easy

'create table in you database

CREATE TABLE mstemp(
	empcode numeric(18, 0) NOT NULL,
	fname nvarchar](50) NULL,
	lname nvarchar(50) NULL,
	doj datetime NULL
	)
 

'write the following code in your aspx.vb page.

 
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim con As New SqlConnection("Data Source=mydatasource;Initial Catalog=db_emp;Integrated Security=True")
        If con.State = ConnectionState.Closed Then
            con.Open()
        End If
        Dim cmd As New SqlCommand("insert into mstemp (empcode,doj)values(@empcode,@doj)", con)
        cmd.Parameters.AddWithValue("@empcode", 4)
        cmd.Parameters.AddWithValue("@doj", DateTimePicker1.Value)
        cmd.ExecuteNonQuery()
        con.Close()
        MessageBox.Show("Saved")
    End Sub
End Class
 

 
'Enjoy

 
  Permalink  
v3

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 505
1 OriginalGriff 248
2 ChintanShukla 185
3 Richard Deeming 175
4 Bhavik_Patel 170
0 Sergey Alexandrovich Kryukov 8,688
1 OriginalGriff 7,237
2 CPallini 2,598
3 Richard MacCutchan 2,080
4 Abhinav S 1,888


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 14 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100