datetime format problem when passing to datagrid


I got this error when trying to display dtaes from my MSql server
"Cast from type 'DataRowView' to type 'Date' is not valid"the sql erver type name is datetime

here is what I use to format the date to display
<asp:TextBox id=txtdateFrom runat="server" Width="70px" Text='<%#DataBinder.Eval(formatdatetime(Container.DataItem,"UTIL_DATE_FROM"),vbshortdate)%>'>
and the eror I get
Cast from type 'DataRowView' to type 'Date' is not valid

so i try
<%#DataBinder.Eval(Container.DataItem,"UTIL_DATE_FROM","{0:dd/MM/yy}") %>

here no error but no display....

what am I doing wrong..?



Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.




HTH, Nauman.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CostlessAuthor Commented:
hello nauman,

i did what you suggest  and now got this error
"Compiler Error Message: BC30456: 'ToShortDateTime' is not a member of 'Date'" I am using and VB.Net in code behind ...
CostlessAuthor Commented:
hello nauman,

i did what you suggest  and now got this error
"Compiler Error Message: BC30456: 'ToShortDateTime' is not a member of 'Date'" I am using and VB.Net in code behind ...
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Woops sorry it should be ToShortDateString() instead of ShortDateTime()

CostlessAuthor Commented:
hummm .. no error but no data , and I known that I query a row with data in it ..

that what I do :
        dbUtils = New DbUtils
        Dim myDateUtilTable As DataTable

        Dim strDateID As String

        strdateID = "17"

        myDateUtilTable = dbUtils.getDateUtilData(strdateID)

        DataGrid2.DataSource = myDateUtilTable

pretty simple just bring back a grid were a couple dates are displayed and the user will have the possibility to update or add another row ...

II hope this not a problem because I am using MySql server .. we have Java app tied to that DB as well ..


CostlessAuthor Commented:
Hello Nauman ,

great it work very well , it was my mistake I remove a "'" when pasting ....

just one more quesion ..  should I use the same when user update or add a new date....and pickup the value in the code  behind ...? what will b the best way to go about it ..

Thank's for your help ..

When you save the data its recommended that you also save the time. For the display purposes, you can format it according to the requirements :)  DateTime.ToShortDateString() can be used to save the records in the database if you want only the date part.

best, Nauman.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.