Click here to Skip to main content
12,754,090 members (29,230 online)
Rate this:
Please Sign up or sign in to vote.
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 2:30am
Updated 14-Jul-11 2:35am
Prerak Patel141.9K
Rate this: bad
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") + "')"
Rate this: bad
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[^].
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

'Try this its very easy

'create table in you database

	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
        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)
    End Sub
End Class



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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 14 Jul 2011
Copyright © CodeProject, 1999-2017
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