2010/07/08

Distinct in DataTable or DataView

How to remove duplicated data? Suppose I have a DataTable (dtMembers) looks like this:
IDNameCityZipCode
01KennyLA12345
02PeterCA54321
03JohnNY13125
04JimmyNY13125







Using the following two lines of codes if you want to get the non-duplicated city list:
string[] columnNames = new string[] { "City" };
DataTable dtCity = dtMembers.DefaultView.ToTable(true, columnNames);
The result will be "LA, CA, NY".

Take a look of the DataView.ToTable() method and this discussion.

2010/04/22

[SSRS 2005] One table uses two DataSets by using Multivalue Parameter

It's not possible that one report item (table, matrix, list... etc) can use two different datasets. Most people will suggest you to merge them into one dataset, but that doesn't work for me because they are not from the same database.

In my case, one dataset is coming from SQL 2005, and another one is coming from OSIsoft PI Server. I want to create a table that display hourly data for each day by using these two datasets. Not only so, some data are calculated on the fly by refering them. It's like mission impossible to create a report like this: these two datasets don't know each other, and one table cannot be assigned two datasets.

Here is how I solved this problem.

2010/04/06

Get .Net Color from Hex Color (Hex string)

It's easy but also easy to forget. I put it here as a note for myself. :)
Label1.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFC0FF");

2010/03/26

[ASP.NET]The DataSourceMode of SqlDataSource

By default, the DataSourceMode of the SqlDataSource is DataSet. Here is how to retrieve the dataset from the SqlDataSource control:
DataTable dt = ((DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty)).ToTable();
or
DataTable dt = ((DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty)).Table;

If you set the DataSourceMode to DataReader, here is how to read the data:
IDataReader reader = (IDataReader)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
while (reader.Read())
{
//your code here
}
reader.Close();
reader.Dispose();

2009/12/12

[ASP.Net]Dynamically assign your page's background image

I would like to change/assign a page's background image depends on some conditions, and here is what I did.
1.Assign an id to the body and add the runat="server" to it.

2.Add the following code to your code-behind (you can put it in the Page_Load event)
if (ConfigurationManager.ConnectionStrings["MyWebsite"].ConnectionString.Contains("test"))
body1.Style.Add("background-image", @"url(Images/test.jpg)");
else
body1.Style.Add("background-image", @"url(Images/production.jpg)");
Modify the if statement to meet your needs.