|
-
Nov 9th, 2012, 01:43 PM
#1
Thread Starter
New Member
Mask Edit Box
I have a few Mask Edit Boxes in my program with a mask if ##/##/####. I had the column that the msktxtb was binding to set to nvarchar data type but kept receiving error:
String was not recognized as a valid datetime. Couldn't store < / /> in Column. Column is not DateTime data type.
I change the appropriate columns data types to datetime datatypes and now I am receiving this error:
The conversion of a char data type to a datetime data type resulted in an out of range datetime value.
Also my msktxtb do not recongize a single digit date for the day.
Example:
If I input 11/09/2012 into the msktxtb when the cursor moves from the msktxtb date shows as 11/92/012
How do I get the msktxt to recongize the date as 11/09/2012? What is the appropriate data type for ##/##/####?
-
Nov 9th, 2012, 01:49 PM
#2
Hyperactive Member
Re: Mask Edit Box
Am I the only one who hasn't heard of a mask edit box? Are you talking about a textbox with masked input? A textbox with restricted input to only the ##/##/#### format? What's the column you speak of, part of a datagridview, sql, access?
-
Nov 9th, 2012, 01:53 PM
#3
Thread Starter
New Member
Re: Mask Edit Box
In the toolbox in vs 2005 its called MaskedTextbox. Yes a textbox restricted to format ##/##/####. Sql Server and the column is also in the datagridview.
-
Nov 9th, 2012, 02:02 PM
#4
Hyperactive Member
Re: Mask Edit Box
There is just a 'date' datatype in sql (not sure of datagridview). I've never worked with a masked textbox, so I'm not sure what's going on there. What's the code like where you take your masked textbox text and insert it into sql/datagridview. Maybe something is happening there we can fix?
Edit: Are you converting your textbox text into a valid date/datetime before using it?
-
Nov 9th, 2012, 02:17 PM
#5
Thread Starter
New Member
Re: Mask Edit Box
Heres my code for inserting into SQL
Code:
u.ExecuteSQL(SqlConn, "INSERT INTO tblRepair (CustomerID, TrackNo, PONo, POLine, SupplierInDate, QtyRecieved, EstRepairPrice, ScheduledShipDate, RescheduledShipDate, PartDescript, PartNo, NewPartNo, TotalScrap, NewSerialNo, SerialNo, ScrapReason, Status, Comments, HAType, QtyShipped, QtyShipScrap, QtyShipReplace, SupplierOutDate, ShipperOut, ABW, FlightNo, DeliveryNo, InvoiceNo, InvoiceDate, InvoiceDueDate, InvoiceAmt) Values ('" & Me.txtbCustID.Text & "', '" & Me.txtbTrackNo.Text & "', '" & Me.txtbPONo.Text & "', '" & Me.txtbPOItem.Text & "', '" & Me.mskSupInDate.Text & "', '" & Me.txtbQtyRec.Text & "', '" & Me.txtbRepairPrice.Text & "', '" & Me.mskSchedShipDate.Text & "', '" & Me.mskReschedShipDate.Text & "', '" & Me.txtbPartDes.Text & "', '" & Me.txtbPartNo.Text & "', '" & Me.txtbNewPartNo.Text & "', '" & Me.txtbTotalScrap.Text & "', '" & Me.txtbNewSerial.Text & "', '" & Me.txtbSerialNo.Text & "', '" & Me.txtbScrapReason.Text & "', '" & Me.txtbStatus.Text & "', '" & Me.txtbComments.Text & "', '" & Me.txtbHAType.Text & "', '" & Me.txtbQtyShipped.Text & "', '" & Me.txtbQtyScrapShip.Text & "', '" & Me.txtbQtyReplacedShip.Text & "', '" & Me.mskSupOutDate.Text & "', '" & Me.txtbShipperOut.Text & "', '" & Me.txtbAWB.Text & "', '" & Me.txtbFlightNo.Text & "', '" & Me.txtbDeliveryNo.Text & "', '" & Me.txtbInvoiceNo.Text & "', '" & Me.mskInvoiceDate.Text & "', '" & Me.mskInvoiceDueDate.Text & "', '" & Me.txtbInvoiceAmt.Text & "')")
I dont have any code in place for converting my text into valid datetime before using it, thats why I orginally had my columns set to nvarchar data type.
-
Nov 9th, 2012, 02:18 PM
#6
Re: Mask Edit Box
The correct mask is 00/00/0000 (known as ShortDate) but note that this is still a string value. To make a Date variable you will need to use one of the Date.Parse methods.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Nov 9th, 2012, 02:21 PM
#7
Thread Starter
New Member
Re: Mask Edit Box
Would I put the Date.Parse method in the click event of the msktxtb or some where else?
-
Nov 9th, 2012, 02:27 PM
#8
Hyperactive Member
Re: Mask Edit Box
I believe before entering into sql. In your query you should be able to use Date.Parse(Me.mskSupOutDate.Text). I think that's the right textbox...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|