Sunday, March 25, 2012

Data entry in a datetime field.

My other thread containg this same topic seems to have some error. It doesn't show up in the main 'SQL Server Database Engine' group at all. So I had to start a new thread instead.

Here's the link to the original - http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1136124&SiteID=1

Here are the contents of the same -

Post#1

Orginally posted by me -

Hi,

I am using SQL Server Management Studio Express for creating my database. I also use the GUI tools for data entry instead of using T-SQL. Whenever I try to enter a value in a field that has a smalldatetime data type, it gives me an error message -

"Invalid Value for cell (row 1, column 2). The changed value in this cell was not recognised as valid. .Net Framework Datatype: Datetime Error Message: Index was outside the bounds of the array. Type a value appropriate for this data type or press ESC to cancel the change."

Now I have tried entering all different combinations in which one can enter a date or a time or both, including in the format I have specified in the windows regional settings, but I always get the same error message.

How do I input data into the field?

Post#2

Originally posted by Jens K. Suessmeyer -

Hi,

you are using a format SQL Serve ri snot expecting. Which User language did you configured for the accessing user and which date are you trying to insert ?
HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

Post#3

Originally posted by me -

Hi,

I use only English as the default language for all programs, OS included. The date in question is not just one particular date, it is any date or time value, and I've been facing this issue ever since I started using SQL Server Express a year ago. Only I haven't used it much since, and need to seriously develop something now, that I bothered to ask the question here.

Some examples of the values I tried entering yesterday, and none of them worked. (I got the same error message for each value) -

1-1-2007

01-01-2007

01/01/2007

01,01,2007

01:01:2007

Jan 01, 2007 (this is the format I have specified for short date in the Win regional settings - MMM dd, yyyy)

I even tried entering time alongside with all those above figures in the format -

11:35 PM

11:35 AM

23:35

The only time value(s) I didn't try was/were - hh:mmTongue Tieds tt - which is the time format specified in my Win regional settings, neither standalone, nor with the date values.

I also tried entering a time value standalone, without the date. Still no go.

(Also, as I have gleaned from previous posts, if all goes well and SQL Server accepts your data, then if you enter just a date value in a datetime field, then the field automatically gets populated with the value of the system time at that moment, and if you enter just a standalone time value, then the date part will be filled by the system date value on the date of the entry. Am I correct so far?)

Now I'm in a real fix because of the inability to enter date/time values.

Could you please help me out?

Post#6

Originally posted by me -

I don't understand. I can enter the datetime values in all the above mentioned combinations if I use an Insert or Update statement using T-SQL, but I can't seem to enter data in the datetime/smalldatetime fields at all if I try to use the GUI of Management Studio Express to enter data. (right click the table, select show table, and the grid view pops up). Ditto for using GUI tools of Visual Studio Express. Is this a bug in the Visual Studio (Express) software?

Also, my other concerns are, once I develop a front-end for data entry using VB, will I face the same issues with data entry in the datetime fields using the GUI of the front end? I can't test that right now, because I'm still learning VB, and cannot create the front end just yet.

Post#7

Originally posted by me this afternoon, but it never showed up on the page -

Alright, I have done a complete reinstall of Win XP, and have also reinstalled SQL Server Express. Prior to this, I had SQLExpress SP1, but now I have directly installed SP2.

Now I continue to face the same issue. SQL Server will not accept any value for any datetime field, unless it is entered as an SQL insert statement. It won't accept the value entered in the exact same format as the insert statement from the GUI mode of Management Studio Express, nor will it take any values from any GUI developed using VBExpress and the fill dataset method. It throws an error everytime. I don't know any other way of databinding and updating/inserting using VB at this time.

I am at my wits' end because of this. I ask again, is this a bug in SQL Server Express? If so how do I report it to MS and get my issue resolved? If not, even then how can I solve this problem?

Could someone please help me out? I am stuck and cannot use the product at all, without the datetime field.

What's the matter? I've created 2 threads for this topic, but it seems no one wants to touch it with a ten-foot pole. Why isn't anyone addressing this issue and giving me a reply on either of my threads?|||

You're probalby not getting a reply because your issue doesn't make sense. There seems to be a terminology issue here... You keep saying that the date value can only be inserted via an Insert statement - well, that's the only way to add new records to a database. An Update statment will work as well if you are updating an existing record.

Date controls are provided that support databinding and the datagrid also supports datetime entries. Perhaps you need to do one of the VB training walkthroughs on data access. Most likely you have a problem with your core data access structure and this datetime issue is just a side effect.

|||

No, it is not a terminology issue. Allow me to demonstrate.

(God bless ImageShack, I wasn't aware of it when I posted this issue in my original thread).

(I'm using SQL Server 2005 Express SP2 and Management Studio Express)

Observe the data in the database as it stands. The view is in Management Studio Express, and I selected the table in Object Explorer, right clicked it, and selected Open Table. The table opens in a datagrid view in the results pane.

http://img217.imageshack.us/img217/3618/datetime1yf0.jpg

Now, I try to insert a record using the same results pane. Note that everything is entered fine, till I get to the datetime field. (I am using the right arrow key to move to each succesive field, after I have entered data in the previous field). I have entered the data in the datetime field. So far so good.

http://img441.imageshack.us/img441/6154/datetime2fc9.jpg

Now note, the second I click the left arrow key, to indicate that I have finished entering data in the field, and that I need to go to another field, I get the following error message.

http://img227.imageshack.us/img227/377/datetime3sq6.jpg

So I have to hit escape twice to get rid of all the data I tried to insert, and we get back to the image displayed in the first link I posted above.

In this test design, I have kept the datetime field to allow nulls, so I am bypassing the field altogether, just to demonstrate that I can enter the rest of the record, as well as the rest of the datatypes perfectly well. (My issue relates to both smalldatetime, and datetime types).

http://img441.imageshack.us/img441/408/datetime4ou5.jpg

Now, note, I am going to copy the datetime value from the above record, and paste the exact same value into the current record I am inserting, but I still get the same error. (The above records were inserted using insert statements from the query pane).

http://img441.imageshack.us/img441/6073/datetime5kl5.jpg

I tried to paste the copied datetime value from the above record into the record below, where I had left it null. Get the error again.

I tried to paste the copied value in a new record I created below, leaving the null value in the above record intact, and I still get the same 'ol error message.

http://img441.imageshack.us/img441/5144/datetime6ui9.jpg

http://img228.imageshack.us/img228/8219/datetime7vm1.jpg

Now, on to VBExpress. We open a project first. Now we go to the database explorer pane, go to our database, select the table in question, right click and select 'show table data' to get this tab -

http://img408.imageshack.us/img408/3094/datetime8er3.jpg

Same ol' story here as well, so I won't go into the details like above. Just adding a record here as well, getting to the date value, entering it and hitting the right arrow key, and this is what I get, here as well.

http://img228.imageshack.us/img228/4053/datetime9tz7.jpg

Now, I tried databinding the fields to textboxes and datetimepickers in a form once, and then tried running it, and entered a date value. It corrupted my entire .mdf file as well as the log file, and I had to restore the database from a backup. It was a lot of hassle. So I don't fancy attempting doing it again, for the purpose of demonstration. I think you guys get the general idea anyway.

(Please pardon the calculations in the rate x qty= amt, I entered everything in a hurry, and didn't pause to think how many zeroes there were in the quantities. That's why the wierd amounts. I noticed only when it was too late.)

(I haven't entered any records between purchase no 1 and 21, values are entered arbitrarily. It is the PK field).

(I also had to blacken out my machine name for security issues).

I hope now people have a better idea of what this issue is.I have elaborated the issue quite lucidly. Hopefully, it is a bug, and will be fixed my MS soon.

|||That is a better explaination - thank you. However, I can't reproduce the problem. The SQLExpress data base should allow you to enter the value as intended. It sounds like your database and/or development environment are corrupt somehow... Granted, I only tested creating a SQLEx database from within VS (full version), but the table viewer in VS allowed me to enter the date "1-2-2007" without a problem.|||I don't understand how it could get corrupted everytime. I have installed SQL Express non-service pack version, I have at one point used both SP1 and SP2 (each instance was preceeded by a full system/OS reinstall), yet I faced the same issue everytime.|||

You are installing US-EN versions of SQL and VS right?

When you do a fresh install, are you only installing Windows, Visual Studio, SQL Express, and necessary drivers and updates? No extra software like security or other apps? You want to be sure there isn't a conflict. Also, is your software legit (legal copy of windows, vs, etc)? You might even try a different computer (bad harddisk or ram could result in recurring issues) with fresh downloads of the installers for VS and SQL (corrupt installers). Granted, these are unlikely fixes, but I'm out of suggestions.

When no one else reports the same issue, and we can't reproduce it, it almost always means its something specific to your computer.

|||I am not able to duplicate your issue.

You must have a trigger or a FK or something which is causing the error you are seeing. "Array out of bounds" should not be generated by a datetime field. Even though, I realize, the error is saying it comes from that field, it must be doing something behind the scene causing the error.

Script out your table and post it here.

Also, I see a red ! on your images from the BILLID field. What does the ! say? That might actually be the problem.
|||

Reed,
Yup, both are the US-En versions.

I have 2 totally different computers, both running Win XP Pro though. One is Intel Celeron 800 MHz based, with only 256 MB of memory, and the other has an AMD Opteron 165 with a gig of ram. (Both are home computers, and yes, I did manage to run SQL Server on the older machine satisfactorily, but have given up on it since I got the new machine). I have faced the exact same issue on both systems. So I don't think it could be machine specific. Although, I never tried it on a fresh install of Win XP with only the drivers and SQLExpress and VBExpress. Since these are home machines, I have a ton of other stuff installed on them.
And I reserve the installation of SQL Server and VB for last, since I don't include them in the Norton Ghost image that I make of my installations with all apps installed and settings tweaked.


Tom,
I don't know how to create triggers yet, so there are none in any of my databases. I face this issue in every single (datetime or smalldatetime) field in every single table in every single database attached to SQLExpress, regardless of whether I have specified Foreign Key, or even Primary Key constraints or not.The red exclamation mark just notes that changes to the database (such as updates or inserts) haven't been saved yet.
(I checked the mouse hover tip and it says "This Cell has changed. The change has not been committed to the database. The original data is NULL." NOthing to worry about. It does that to all fields that are set to allow nulls, I think.


Something about what Reed said set me thinking. I tweak almost every OS setting to my exacting requirements whenever I first install it. I have tweaked the datetime settings of Windows. I also disable unnecessary services. Does that have anything to do with the way SQL Server is behaving? What windows services should be running for SQL Server to run without hiccups? Is there any incompatibility with tweaked windows datetime settings?

Here's the scripted table as requested. It's the same as the one I've used in my example pics. I have removed the database name wherever it appears for security and privacy concerns, so don't be alarmed or think that the issue is because I don't have the dbname specified where it ought to be. ;-) Big Smile
(Note, I added the check constraints and the last column after I posted the pics).

Code Snippet

USE [.MDF]
GO
/****** Object: Table [dbo].[Purchases] Script Date: 06/14/2007 17:00:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Purchases](
[PurchaseNo] [bigint] NOT NULL,
[BillNo] [varchar](50) NULL,
[Date] [datetime] NULL,
[Broker] [varchar](50) NULL,
[ShareName] [varchar](50) NULL,
[Quantity] [int] NULL,
[Rate] [numeric](12, 2) NULL,
[Amount] [numeric](12, 2) NULL,
[Old] [char](1) NULL,
[Balance] [char](1) NULL,
CONSTRAINT [PK_Purchases] PRIMARY KEY CLUSTERED
(
[PurchaseNo] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[Purchases] WITH CHECK ADD CONSTRAINT [Balancecheck] CHECK (([Balance]='e' OR [Balance]='p' OR

[Balance]='f'))
GO
ALTER TABLE [dbo].[Purchases] CHECK CONSTRAINT [Balancecheck]
GO
ALTER TABLE [dbo].[Purchases] WITH CHECK ADD CONSTRAINT [Oldcheck] CHECK (([Old]='n' OR [Old]='y'))
GO
ALTER TABLE [dbo].[Purchases] CHECK CONSTRAINT [Oldcheck]


|||

Ok, it may very well be a result of "tweaking" the windows datetime settings. The services thing wouldn't cause it - if you disabled a service that SQL needed, it wouldn't run.

If you know precisely what changes you've made to the default date/time settings you should undo them one at a time and test the app until it works. That would at least let you understand which tweak caused the issue. Its possible that the change you made broke the table editors in question and that the failure is expected. It is also possible that this is indeed a bug in the software due to an oversight in properly checking the

System.Globalization.DateTimeFormatInfo

before trying to parse a date.

See where undoing your tweaks gets you. If you have the resources, it might be even better to start with a clean, fresh install of windows and then apply your tweaks one at a time until the program breaks.

|||I am unable to duplicate your problem using the code you posted on SQL 2005 SP1 (not SQLExpress but should be the same).

What do you mean by "tweaked datetime settings"? What exactly did you change and how? And I guess more importantly why?

I THINK the Mgt Console uses the Windows date format to know what to expect. If you changed the format, that is very likely your issue.

|||

This is what has been tweaked. The values are not the default ones that windows supplies when doing a fresh install. I don't recall what the default values are.

http://img233.imageshack.us/img233/8202/date1wi1.jpg

http://img233.imageshack.us/img233/2007/time1li4.jpg

Also, I don't think changing the date time settings could be an issue, because, as noted in my very first post above, I have tried entering all these combinations of values using insert statements, and they all worked fine.

1-1-2007
01-01-2007
01/01/2007
01,01,2007
01:01:2007
Jan 01, 2007 (this is the format I have specified for short date in the Win regional settings - MMM dd, yyyy)
I even tried entering time alongside with all those above figures in the format -
11:35 PM
11:35 AM
23:35

I have tried entering these very combinations through both insert statements, and the GUIs. Only one works. So it doesn't really matter if I've changed the way dates are displayed in Windows, does it? The GUI should still accept the values, especially if the code is accepting the same values.

|||

reachrishikh wrote:

...

Also, I don't think changing the date time settings could be an issue, because, as noted in my very first post above, I have tried entering all these combinations of values using insert statements, and they all worked fine.

...The GUI should still accept the values, especially if the code is accepting the same values.

I don't think this is the case... SQL has it's own formats that it expects values to be entered in. I don't think it takes its formats from Windows. However, text input boxes, such as those found in a data grid of some kind, would most likely be affected by Windows format settings. I might be wrong here, but this is what makes me think it is a settings problem and not an issue with SQL.

There's still the possibility of some other software conflict or corruption since you haven't tried a clean install (using a disk image doesn't count as a "clean" install).

|||

So could any of you please supply me with the default windows date and time settings, so I can (for the time being) revert to the original settings and see if it works?

Also, I haven't got the time this week, so I'll set aside a day next week, and try doing the clean install as you guys suggested, and see if I still get the error even then.

|||

Orignal 2 digit year was 2029

Short date format was M/d/yyyy

Date separator was /

No comments:

Post a Comment