473,486 Members | 2,394 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Inserting Datetimepicker in SQL Database

7 New Member
Hi,
I have a problem while inserting Datetimepicker value into Sql database.The value which gets inserted in database is 01/01/1900 which is the wrong one ,as I wanted today or current date to get inserted in database.
i am using VB.Net 2003 as my front-end and MS SQL 2000 as my back-End.
Please help me....
Aug 23 '07 #1
9 29748
dip_developer
648 Recognized Expert Contributor
Hi,
I have a problem while inserting Datetimepicker value into Sql database.The value which gets inserted in database is 01/01/1900 which is the wrong one ,as I wanted today or current date to get inserted in database.
i am using VB.Net 2003 as my front-end and MS SQL 2000 as my back-End.
Please help me....
i have some question..
Are you picking date from datetimepicker??
Do you want to insert Today's date everytime???Then why are you using datetimepicker if the date is fixed???

two possibilities.....
1.If you are picking date from datetimepicker then use the following code

Dim myDate as Date
myDate=myDatepicker.Value

while inserting write code like...........
Insert into myTable (mDate) Values (#" & myDate & "#)

2. if you only want to insert current date then use getdate() method
like...
Insert into employee values (4,'John',25, getdate())
Aug 23 '07 #2
cravish
7 New Member
i have some question..
Are you picking date from datetimepicker??
Do you want to insert Today's date everytime???Then why are you using datetimepicker if the date is fixed???

two possibilities.....
1.If you are picking date from datetimepicker then use the following code

Dim myDate as Date
myDate=myDatepicker.Value

while inserting write code like...........
Insert into myTable (mDate) Values (#" & myDate & "#)

2. if you only want to insert current date then use getdate() method
like...
Insert into employee values (4,'John',25, getdate())

I am picking date from datetimepicker.But after taking your suggestion i am getting this error for date 23/08/2007 "The name #23 is not permitted in this context.Only constant,expressions,or variable are allowed here.Column names are not permitted".One thing i forgot to specify is the datatype for date in database which is smalldatetime.
Aug 23 '07 #3
dip_developer
648 Recognized Expert Contributor
I am picking date from datetimepicker.But after taking your suggestion i am getting this error for date 23/08/2007 "The name #23 is not permitted in this context.Only constant,expressions,or variable are allowed here.Column names are not permitted".One thing i forgot to specify is the datatype for date in database which is smalldatetime.
Please post your code......
Aug 23 '07 #4
cravish
7 New Member
Please post your code......
strQry = "insert into gin_mst(GINDate,GinNo,........,userId,LCNo)"
strQry = strQry & "values(#" & Format(myDate, "dd/MM/yyyy") & "#,'" & Trim(strGINNo) & "',.........,'" & userId & "','" & Trim(cmbLcNo.Text) & "')"
mycommand = New SqlCommand(strQry, myConnection)
ra = mycommand.ExecuteNonQuery


this is the Queery which i am using to insert date.
Aug 23 '07 #5
dip_developer
648 Recognized Expert Contributor
strQry = "insert into gin_mst(GINDate,GinNo,........,userId,LCNo)"
strQry = strQry & "values(#" & Format(myDate, "dd/MM/yyyy") & "#,'" & Trim(strGINNo) & "',.........,'" & userId & "','" & Trim(cmbLcNo.Text) & "')"
mycommand = New SqlCommand(strQry, myConnection)
ra = mycommand.ExecuteNonQuery


this is the Queery which i am using to insert date.
I have forgotten about sql-server.....very very sorry...
try

"insert into gin_mst (GINDate) values('" & Format$(dtpicker.value,
"dd.mm.yyyy") & "')"
Aug 23 '07 #6
cravish
7 New Member
I have forgotten about sql-server.....very very sorry...
try

"insert into gin_mst (GINDate) values('" & Format$(dtpicker.value,
"dd.mm.yyyy") & "')"
I tried what you have suggested but still its storing 01/01/1900 in database.
Aug 24 '07 #7
shiponeye1
9 New Member
Hi, just try with that.

datetime dMyDate=dtpPicker.value

cmdInsert="INSERT INTO MyTable(MyDate) VALUES('" & dMyDate.ToString("dd MMM yyyy") & "')"

you can insert any date in this format.

!!! SHIPON !!!
Aug 24 '07 #8
cravish
7 New Member
Hi, just try with that.

datetime dMyDate=dtpPicker.value

cmdInsert="INSERT INTO MyTable(MyDate) VALUES('" & dMyDate.ToString("dd MMM yyyy") & "')"

you can insert any date in this format.

!!! SHIPON !!!

Yes i know.... but i am using smalldatetime as my data-type.
If i use the above query it give an error for datatype i.e
"The conversion of char data type to smalldatetime resulted in out-of-range smalldatetime value.The statement has been teminated."
Aug 24 '07 #9
spidervb
3 New Member
@shiponeye1
its work ,,,, thanks :)
Sep 26 '13 #10

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

Similar topics

0
1394
by: Tom Rahav | last post by:
Hi. I have a DateTimePicker on a win form in VB.NET 2003, and I have a database table that contains different dates as records. What I want to do is detect what dates are exist in the database,...
9
3930
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
2887
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...
7
6183
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...
1
3197
by: Kevin | last post by:
I have put a VS2005 sample project up here: http://www.kevinandkiran.com/CSharpApplication.zip (its only 50k) Basically I have a class that contains a date property, which is initialised to...
1
2966
by: venkatraotammineiii | last post by:
Dear all, I am working C#.net2005.I Have problem that is i have one datetimepicker and combobox.now i have msaccess databse.in that database i have datatime field.but i need to get datetime into...
6
2543
by: Kyote | last post by:
I'm using a DateTimePicker for date fields in an Access db Membership app. Some of the date fields are empty, meaning they haven't been filled out yet, or they cannot be. But when a record is read...
0
1716
by: Darin | last post by:
I have a form that has a tab control, that has about 10 different tab pages. On tab page 3 is a datetimepicker. I am reading an SQL database and setting tdate.text={datefromsql}. My problem...
4
3281
by: jehugaleahsa | last post by:
Hello: We were hoping to allow users to have DateTimePicker value null so that a unused date is stored on a Database. Does the control support this? I am pretty sure it doesn't. How would you...
0
6967
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
7180
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6846
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
7341
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...
1
4870
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
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
600
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.