469,271 Members | 1,023 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

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
{
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
Jan 17 '07 #1
1 1278
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/subscripti...ult.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/subscripti...t/default.aspx.

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

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
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.