date vb.net2005 & sqlserver 2005
-
hi guys maskedtextbox1.mask = "##/##/####" mskedtextbox2.mask = "##/##/####" i am using maskedtextbox for getting i/p of date. i have taken mask properties short datetime. my data is stored in sql server 2005 where i have taken data type is varchar(10) in dd/mm/yyyy format (28/08/2007 & 31/08/2007). my problem is that when i execute the sql query for the selected period in maskedtextbox it does not show correct data. e.g. sql_str = "insert mdate into xyz (select mdate from abc where " & _ "mdate between" & " '" &maskedtextbox1.text& "' and '"&mskedtextbox2.text&"'" "and flag= '" & mflag & "')" or using where condition it is not executing correct data. can i get where i am wrong ? if is there any more suggestion for me suggest me.
Thanks bye
-
hi guys maskedtextbox1.mask = "##/##/####" mskedtextbox2.mask = "##/##/####" i am using maskedtextbox for getting i/p of date. i have taken mask properties short datetime. my data is stored in sql server 2005 where i have taken data type is varchar(10) in dd/mm/yyyy format (28/08/2007 & 31/08/2007). my problem is that when i execute the sql query for the selected period in maskedtextbox it does not show correct data. e.g. sql_str = "insert mdate into xyz (select mdate from abc where " & _ "mdate between" & " '" &maskedtextbox1.text& "' and '"&mskedtextbox2.text&"'" "and flag= '" & mflag & "')" or using where condition it is not executing correct data. can i get where i am wrong ? if is there any more suggestion for me suggest me.
Thanks bye
As you are storing the dates as text, you can't do any calcualtions on them (including comparison). You could convert every value to a date in the query, but that's very inefficient. Store the values as dates in the database, not text.
--- "Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams
-
As you are storing the dates as text, you can't do any calcualtions on them (including comparison). You could convert every value to a date in the query, but that's very inefficient. Store the values as dates in the database, not text.
--- "Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams
-
hi but it is working in vb6. so i think that it is possible in vb.net also. if i use dtpicker then is it possible ?
Thanks bye
VB6 handles date/time differently than VB.NET and SQL Server. Who cares if it "used to work" under VB6 since you're not using it now. You absolutely can NOT store dates in the database as strings and expect to be able to do comparisons and math on those dates, when they are not being treated as dates. Instead, they are treated no differently than if you stored "iwjf948fu04f" as your date. Using a different control will have no effect since you are STILL storing dates as strings and not actualy datetime values in the database.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
VB6 handles date/time differently than VB.NET and SQL Server. Who cares if it "used to work" under VB6 since you're not using it now. You absolutely can NOT store dates in the database as strings and expect to be able to do comparisons and math on those dates, when they are not being treated as dates. Instead, they are treated no differently than if you stored "iwjf948fu04f" as your date. Using a different control will have no effect since you are STILL storing dates as strings and not actualy datetime values in the database.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Change the data type of database columns to datetime and while storing and changing the values of that field try this statement for dates Date.ParseExact(txtMasked.text,"Format") format means "dd/mm/yyyy" i think it is in your case. the above statement will return a Date object which can be sent to database and then retrieved :)
Salman Sheikh
-
Change the data type of database columns to datetime and while storing and changing the values of that field try this statement for dates Date.ParseExact(txtMasked.text,"Format") format means "dd/mm/yyyy" i think it is in your case. the above statement will return a Date object which can be sent to database and then retrieved :)
Salman Sheikh
And you're telling me this why?? Yeah, but this doesn't solve the underlying problem of storing dates in the database as strings.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007