Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.

Saturday, August 15, 2009

Use a Class to Store ConnectionString

This appears the best way to store database ConnectionString objects in a given Class:


internal static string GetConnectionString(string specifiedConnectionString, bool lookupConnectionString, bool appLevel)
{
//Your Conn String goes here!!
return Factory.ConnectionString;
}

Notice that a static Class is used since we don't need to waste memory instantiating strings.

References: http://forums.asp.net/p/997608/2209437.aspx
Specifically mentioned was to modify the SQLConnectionHelper.cs from: http://download.microsoft.com/download/a/b/3/ab3c284b-dc9a-473d-b7e3-33bacfcc8e98/ProviderToolkitSamples.msi

Use Column Mapping with MappingType.Hidden to Hide Columns in a DataTable

It is possible to use Column mapping with MappingType.Hidden to hide columns in a DataTable of a Dataset before the Fill with the following:

myDS.Tables[0].Columns[i].ColumnMapping = MappingType.Hidden;


Of course, 0 may be substituted with the table name as a string. Unfortunately, this is not very useful if the Fill has already created the DataSet. In that case I would probable just want to use an item template in my data display control (such as a GridView) to output the specific fields. The other option is to run the delete columns on the DataTable, which is simply inefficient. Another losing option is to run a select command on the DataTable, which might have its uses for simply acquiring in memory data as opposed to viewing it.

References: http://www.dotnetspider.com/forum/ViewForum.aspx?ForumId=3888

Create a Column in Excel with Leading 0s

To create a column in Excel with leading 0s given a column A with values 0,1,..., and 12 character string to create, use this formula on the target column:


= RIGHT("000000000000" & A1,12)

The result will be 000000000000,000000000001,...
Then just use the copy, paste special as values technique mentioned earlier.

Reference: http://www.koozie.org/2004/11/excel_leading_z.html

Concatenate two Excel Columns with a Character or String

To concatenate (or join) two columns A2 and B2 into C2 with a hypen (in this case), use this formula in C2:

=A2&"-"&B2

Then copy the results down the column with click and drag downwards to duplicate the formula on the cell. Finally, copy column C and paste special into the target column as values only.

Reference: http://www.pcmag.com/article2/0,2817,33100,00.asp

How to Create GUID from a String

This is an easy way, but esoteric task, to create a GUID from a string:


Guid g = new Guid(string);

Reference: http://www.devnewsgroups.net/dotnetframework/t2650-convert-string-guid.aspx

Using Vista to Add a User Account to a Group

Here is a helpful description of how to add a user account to a group. Of course you probably need Vista Business or Ultimate.

Reference: Using Vista to Add a User Account to a Group

Tuesday, April 14, 2009

Getting Started With Microsoft Charts

I just ran across a tutorial on getting started with Microsoft Charts for ASP.NET 3.5. The pre-requisite is to download the chart.exe from http://code.msdn.microsoft.com/mschart Specifically, I clicked the "Chart Controls for .NET Framework" link on that page to download MSChart.exe.

Microsoft offered this in response to Googles Charts by buying Dundee's Charts that was for .NET 2.0. Note, this new one is for 3.5.