Click here to Skip to main content
15,907,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dataset which fetches the information from a Registration table. This able has a column "RegistrationDate".

I am trying to get the data in the dataset - in it I want to retrieve just the date part of the column.

VB
for each drow as data.datarow in ds.tables("Registration").rows
 dim dt as datetime = ctype(drow.item("RegistrationDate"),datetime)
 drow.item("RegistrationDate") = dt.date
next

I know something is wrong, because when I read the dataset again, I do not get the changed value.
Posted
Updated 22-Aug-10 8:12am
v2

Did you tried to debug?

First check if the date was fetched correctly in string format.
Then check if the casting to datetime was correct such that you didn't loose the time
Lastly, use the Dates toLongDateTimeString() proerty if needed.

VB
drow.item("RegistrationDate") = dt.date

Here after dt, press the dot and check for available properties to get date string. Further, once the string is casted to datetime, you can specify specific format to present the datetime.
 
Share this answer
 
<br />
 Dim dt As Data.DataTable = ds.Tables("Registration")<br />
        Dim lst As New List(Of DateTime)<br />
        For Each _row As Data.DataRow In dt.Rows<br />
            lst.Add(_row("RegistrationDate"))<br />
        Next<br />
 
Share this answer
 
hello,

I think the code is fine. It should throw an exception if the date is not in correct format. Make sure the applciation does not re-populating the "Registration" table after the manipulation.
 
Share this answer
 
Immediately after changing the date in the dataset, i am binding it to a gridview. I have debugged, the value shows correctly while debugging, but when binding it to the gridview, i still get the old value!
 
Share this answer
 
<asp:datagrid id="DataGrid1" autogeneratecolumns="false" xmlns:asp="#unknown">
EnableViewState="False" runat="server">
<columns>
<asp:BoundColumn DataField="RegionalID" />
<asp:BoundColumn DataField="RegistrationDate"
DataFormatString="{0:MM/dd/yyyy}" />
</columns>
</asp:DataGrid>
 
Share this answer
 
I'm sorry i did not mention, i did try the dataformatstring but it does not work. THe date is still shown with the time string!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900