You must Sign In to post a response.
  • Category: Windows

    DatetimePicker not accepting values from database

    Hello,

    I am developing a VB.NET project.

    During form show, the datetime picker I placed is showing today's date.

    I have a bill no search button. While retrieving values from DB, the datetimepicker should show the bill date. Instead of that, Its showing the current date. Plz verify the below code.

    _gd = New gbdataDataContext
    Dim _billMain = (From p In _gd.POS_TRX_BILLs Where p.billno = _GbillNo).ToList

    dtbilldate.Value = _billMain(0).billdate.Value

    The above line is executing without any errors. But Instead of showing 1/6/2016(Bill date), its showing current date (20/2/2016).

    I tried also this,
    dtbilldate.Text = _billMain(0).billdate
    but same result.

    Can anyone plz help.

    I using LINQ to get the values from DB.

    Thanks
    Shahul
  • #764695
    I don't find any issues with your code. What I am guessing is you are trying to change the value in wrong place.

    It looks like once you set this value from one place in some other function or from page_load you are overriding this value with current date.

    try to debug the entire code till the end and see if it is again resetting from some other place.


    Otherwise your code should work fine.


    Regards,
    Asheej T K
    Microsoft MVP[ASP.NET/IIS]
    DotNetSpider MVM

  • #764701
    Hai Shahul,
    It doesn't matter or least matters whether you are getting data using Linq or some other sources. The assigning the value to the date picker depends on the formatting.
    You need to have the custom format for the date picker and then you need to define the type of format and then you need to have the same format from the database and then assign.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764706
    Following are some the tips for correct your issue.

    1. I do not see any code for assign the current date.
    Are are you assigning the current date in the page load?
    2. Are you assigning the billing date in the page load
    or Any of the other event.
    3. I thing it is because of the post back.

    if (!Page.IsPostBack)
    {
    }

    If you id not handle the IsPostBack, It may always initialize with the current date.

    By Nathan
    Direction is important than speed


Sign In to post your comments