471,593 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,593 software developers and data experts.

casting question: sorting strings as dates in either dataset or in the presentation layer?

I'm querying Index Server to return search results, both regular properties
and some custom properties I've created. Index Server has this preference
for thinking about information as strings rather than datatypes.If you
really work at it, you can configure Index Server to treat the data as, say,
sortable DateTime datatypes, or integer datatypes. But I'm finding this a
huge pain in the butt, and it bothers me that I'm attaching a bunch of
custom configurations to the server just to get a sort working. It would be
better if this happens in the application.

I'm wondering if I could "fix" my stringy data in either the data layer or
somewhere in the presentation layer: at some point, I want ASP.NET or
ADO.NET to recast the date strings to real sortable datatypes. I'm hoping
someone can give me some guidance on the easiest way to make this happen.

Here's the rough version of what I've got going; much was originally pulled
from the code project. I need some counsel and maybe some code regarding the
best place to make the casts from string data to datatime data, and I need
to know how to implement a reverse chrono sort either using the in-memory
instance of the data, or maybe on the grid.

private string Command
string query = String.Format(@"
SELECT Rank, VPath, DocTitle, Filename, Characterization,
Write, uwnpubdate,uwnvolume,uwnnumber, uwncontentcategory
""c:\Inetpub\wwwroot\ni\search\indexes\myIndex ""')
WHERE NOT CONTAINS(VPath, '""_vti_"" OR "".config""')",
... [other configure-my-query-code ]

private void Search()
// Create a new DataSet and fill it.
this.dbAdapter.SelectCommand.CommandText = Command;
DataSet ds = new DataSet("Results");

// Bind the resulting DataSet.
this.dgResultsGrid.DataSource = ds;

// If all was bound well, display the DataGrid.
this.dgResultsGrid.Visible = (rows 0);

The itemtemplates on the grid use functions to call the data they need:

<asp:HyperLink ID="Hyperlink1" runat="server" NavigateUrl='<%#
<i>Published <asp:Label ID="Label3" Text="<%#
GetPubDate(Container.DataItem)%>" runat="server" /| Vol. <asp:Label
ID="Label4" runat="server"><%# GetVolume(Container.DataItem)%></asp:Label>,
No. <asp:Label ID="Label5" runat="server"><%#
GetNumber(Container.DataItem)%></asp:Label></i><br />
<asp:Label ID="Label2" runat="server"><%#
GetCharacterization(Container.DataItem)%></asp:Label><br />
The inline functions are calling code similar to this:

protected object GetVolume(object value)
string volume = DataBinder.Eval(value, "uwnvolume") as string;
if (volume != null && volume.Length 0) return volume;

return DataBinder.Eval(value, "uwnvolume");
TIA for any help you can offer.

Jan 17 '07 #1
1 1343
Hello KF,

From your description, you're using .NET code to query the IIS indexing
service content and display then through web page. since all the columns in
the indexing content are queried out as string/text, you're wondering how
to convert those typed values(such as Datetime, int) into their actual type
values, correct?

Based on my research, for the .NET DataSet/DataTable, if you want to make
the column values in each row be converted to their actual type, the
original source data should be in XML format which conforms to a certain
dataset schema. For your scenario, your data is some simple formatted text
content, the DataSet/DataTable can not automatically convert it.

One way to convert those data is you first load the content into a
DataSet/DataTable, then create a new DataTable with columns explicitly
defined as those actual type(such as DateTime, Int ....). After that, you
can programmatically loop through the original datatable, and explicitly
convert the certain colums value into their actual format and add the new
values into the new typed DataTable. For example, for datetime value, you
can use DateTime.Parse, for integer, you can use Int32.Parse.... But such
approach is quite expensive and will hit your application's performance.

How do you think on this?


Steven Cheng

Microsoft MSDN Online Support Lead


Get notification to my posts through email? Please refer to

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at


This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 17 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Kevin Davis | last post: by
22 posts views Thread by mike | last post: by
6 posts views Thread by Michael Rodriguez | last post: by
1 post views Thread by richilli | last post: by
reply views Thread by Simon Gregory | last post: by
reply views Thread by =?Utf-8?B?SmVhbi1GcmFuY29pcyBCcmV0b24=?= | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.