Results 1 to 8 of 8

Thread: Mask Edit Box

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    7

    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 ##/##/####?

  2. #2
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    365

    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?

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    7

    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.

  4. #4
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    365

    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?

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    7

    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.

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    7

    Re: Mask Edit Box

    Would I put the Date.Parse method in the click event of the msktxtb or some where else?

  8. #8
    Hyperactive Member
    Join Date
    Nov 2008
    Location
    PA
    Posts
    365

    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
  •  



Click Here to Expand Forum to Full Width