473,836 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ 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 29779
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???The n 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=myDatepi cker.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???The n 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=myDatepi cker.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,expres sions,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,expres sions,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.Te xt) & "')"
mycommand = New SqlCommand(strQ ry, myConnection)
ra = mycommand.Execu teNonQuery


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.Te xt) & "')"
mycommand = New SqlCommand(strQ ry, myConnection)
ra = mycommand.Execu teNonQuery


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$(dtpicke r.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$(dtpicke r.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=dtpPick er.value

cmdInsert="INSE RT INTO MyTable(MyDate) VALUES('" & dMyDate.ToStrin g("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=dtpPick er.value

cmdInsert="INSE RT INTO MyTable(MyDate) VALUES('" & dMyDate.ToStrin g("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
1425
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, and mark then on the DateTimePicker. Does anyone know how can I mark a specific date in the DateTimePicker (which is not the current date)? Thanks! Tom Rahav.
9
3978
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 will not set the value of the control and will leave the checked status of the checkbox to false when a user selects a new date. this works fine when using the control on a win2k machine but if we use it on a win XP box and call
2
2912
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 which the rest of the processing will be based. I have a Windows Form with a DateTimePicker that is bound to this MSAccess database and 'ParmDate' table and column. I have a button on the form that when clicked will update the dataset. I have a...
7
6221
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 the DateTimePicker, since the default is shown. My problem is, if the user does not choose a value from the DateTimePicker (because using the default is good enough), then during database update, the date value is not saved to the database; while if...
1
3239
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/1/1970. I create a project datasource from this and then drag my class onto my form which binds my property to a datetimepicker. However when I set the bindingsource to be an instance of my class at runtime I get the following exception:
1
2992
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 datetimepicker when user click the datetimepicker the data has to come form database and it has to set date form database.based on that date i need get persons are in combobox. means once i click datetimepicker it need to access the data from...
6
2561
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 with empty fields, their connected DateTimePicker's display the current date. Is there any way to have the DateTimePicker show as empty/blank? --- Kyote
0
1744
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 is when I load the page, the datetimepicker displays today's date if the data is loaded and the particular tab page isn't the focused tab page. But, if the data is loaded and the tab page with the datetimepicker is focused, the date is loaded...
4
3306
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 go about representing this to a user so they are not confused? Thanks,
0
9656
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10821
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10527
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9358
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7773
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5812
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4441
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 we have to send another system
3
3102
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.