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

G

Guest

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
{
get
string query = String.Format(@"
SELECT Rank, VPath, DocTitle, Filename, Characterization,
Write, uwnpubdate,uwnvolume,uwnnumber, uwncontentcategory
FROM SCOPE('SHALLOW TRAVERSAL OF
""c:\Inetpub\wwwroot\ni\search\indexes\myIndex""')
WHERE NOT CONTAINS(VPath, '""_vti_"" OR "".config""')",
"/search/indexes/uweek");
... [other configure-my-query-code ]
.....

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

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

// 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:

<ItemTemplate>
<p>
<asp:HyperLink ID="Hyperlink1" runat="server" NavigateUrl='<%#
GetUwnewsUrl(Container.DataItem)%>'><%#
GetTitle(Container.DataItem)%></asp:HyperLink><br>
<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 />
</ItemTemplate>


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.

-KF
 
S

Steven Cheng[MSFT]

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?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



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
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top