Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 14-Jul-11 1:35am
v2

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") + "')"
 
Share this answer
 
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[^].
 
Share this answer
 
'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
 
Share this answer
 
v3

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