Mar 12

Read CSV Into an ADO.NET RecordSet

http://www.daniweb.com/forums/thread38676.html#

DateTime Examples C#

http://www.geekpedia.com/tutorial98_Using-the-DateTime-object.html

C# Dictionary

http://www.vcskicks.com/dictionary.php

Dictionary<string, int> dictionary = new Dictionary<string, int>();

dictionary.Add(“1″, 1);

int j = dictionary["1"];

C# List Examples

http://dotnetperls.com/list

List<int> list = new List<int>();
list.Add(2);
list.Add(3);

Decimal.TryParse and Convert.ToDecimal
http://stackoverflow.com/questions/89203/difference-between-convert-todecimalstring-decimal-parsestring

One factor that you might not have thought of is the Decimal.TryParse method. Both Convert.ToDecimal and Parse throw exceptions if they cannot convert the string to the proper decimal format. The TryParse method gives you a nice pattern for input validation.

decimal result;

if (decimal.TryParse(”5.0″, out result))

; // you have a valid decimal to do as you please, no exception.

else

; // uh-oh. error message time!

This pattern is very incredibly awesome for error-checking user input.

String List string[] to an ArrayList in C#
http://www.daniweb.com/forums/thread82407.html#


string str= "12,13,14,15";
  1. string[] strs = str.Split(',');
  2. ArrayList strsList = new ArrayList();
  3. foreach(string s in strs)
  4. strsList.Add(s);
Sep 14

A friend shared with me today an ASP.NET control for Google maps!

The code can be downloaded and viewed at:

http://res.sys-con.com/story/jan06/171162/source.html

The complete article is available at:

http://be.sys-con.com/read/171162_1.htm

Jul 31

Browsing around on the asp.net forums while doing some VB.NET coding today I ran acrosssome information regarding multiline comments in VB.NET.

In the past VB didn’t offer a resource for multiline comments however bmains postedthat VB.NET 2005 now supports the ”’ comments. That’s ‘ ‘ ‘. Just enter three consecutive’ and you will be able to enter multiple lines of comments.

Jul 31

When using Yahoo! Maps for map development on a local machine it is good to note thatright now the GeoRSS XML overlay method will not allow referencing a local XML fileor using a local URL reference. For example, you cannot refer to http://localhost/mystores.xml TheXML file must be fully accessible via the internet. It appears that the Yahoo! serversfetch the file and the points are then added to the map, not the local machine. Anydevelopment must be done on a remote server or you must make your development machineport 80 available to the internet.

Jul 28

Here’s a really weird error with a quick fix. When you run your ASP.NET 2.0 web appyou will get the following error:

The path ‘/someApp/App_GlobalResources/’ maps to a directory outside this application,which is not supported.

Description: An unhandled exception occurredduring the execution of the current web request. Please review the stack trace formore information about the error and where it originated in the code.

Exception Details: System.Web.HttpException:The path ‘/someApp/App_GlobalResources/’ maps to a directory outside this application,which is not supported.

Take a look at your IIS site home directory. If you have aslash after the directory name then you’ve found your problem.

Apparently the local path cannot have a trailing “\” on itas IIS automatically adds one which causes the error.

Source:

http://forums.asp.net/thread/942453.aspx
 

 

>

Jul 27

When adding an UpdateProgress area to an ASP.NET form you will receive constanterrors unless EnablePartialRendering is set to TRUE for the ScriptManager in yourpage.

See screenshots below for the error and the entry in the aspx page…

 

 

Jul 27

Do you have Firefox or any other browser other than IE installed and each time yourun a debug for an ASP.NET site that browser opens instead of IE? Or wouldyou rather that browser open and not IE?

You can easily set the browser that Visual Studio uses to browse with by followingthese steps:

1) In your web application right click any ASP.NET file in the Solution Explorer
2) Left click “Browse with…”
3) You will be presented with a list of browsers. Here you can select one and clickthe “Set Default” button to set the default for Visual Studio OR you can click the”Browse” button to view this page in the browser you have selected.

See screenshots below:

Jul 25

Question: How can I format numbers and date/times using ASP.NET? For example, I want to formata number as a currency. >


Answer: One of the nice things about VBScript was its built-in formatting functions, suchas FormatCurrency, FormatNumber, FormatDateTime,etc. (For more information on these functions see thisFAQ or, better yet, check out the StringsFAQ Category.)

When creating ASP.NET Web pages with VB.NET, you can still use these functions, althoughyou will need to import the Microsoft.VisualBasic namespace. But whatif you are using C#, or want to start using the new formatting methods available in.NET? To allow for formatting, the .NET Framework contains a general String.Format staticmethod along with .ToString() methods for each object.

So, first off, you can easily convert a non-string data type to a string by usingit’s .ToString method. That is, if you wanted to turn a DateTime variableinto a string you could do:
>

'Create a var. named rightNow and set it to the current date/time
Dim rightNow as DateTime = DateTime.Now
Dim s as String 'create a string

s = rightNow.ToString()

This simple code snippet creates a DateTime variable (rightNow) thatis assigned the current system date/time. A String variable (s) is thencreated and assigned the string representation of the DateTime variable.

The .ToString() contains an overloaded variant that accepts a singleString parameter. This parameter can be used to specify how to format the DateTimevariable. For example, if we wanted to display the date as a three-lettered monthnamethen the day, and then a comma followed by the year in four digits (like Jan 30,2002), we could use the .ToString(formatString) method like so:

'Create a var. named rightNow and set it to the current date/time
Dim rightNow as DateTime = DateTime.Now
Dim s as String 'create a string

s = rightNow.ToString("MMM dd, yyyy")

Pretty neat, eh? Of course the question still remains: “How in the world did I knowto use MMM to display the three-letter abbreviation of a month? The answer,of course, is to hit the documentation. One thing the .NET Framework has an abundanceof is documentation. For a list of special formatting characters for date/time purposes,see DateTimeFormatInfoClass.

Using the overloaded .ToString() method is nice especially when you wantto apply a custom format. However there’s another way to format through the use ofthe String class, which contains a Format method. This method takes aformat string followed by one to many variables that are to be formatted. The formatstring consists of “placeholders,” which are essentially locations to place the valueof the variables you pass into the function. These placeholders assume the form:

{placeholderNumber:formatCharacter}

So if we wanted to format a number into a currency, we could do so by using the followingcode:

'Create a var. named price that will be formatted as a currency
Dim price as Double = 3.1
Dim s as String 'create a string

s = String.Format("{0:c}", price)

This would output: $3.10 (or perhaps something else, depending on your Web server’sglobal locale information – that is, in China it may display a Yen symbol insteadof the dollar sign). In any case, note that the format string contains a placeholder {0:c},which says to make the 0th variable in the list a currency (the c denotingcurrency). If we wanted to format multiple variables in one shot we could do so:

s = String.Format("{0:c} on {1:d}", price, rightNow)

would display:
$3.10 on 1/30/02

Note how the first digit in each placeholder specifies what variable in the proceedinglist to use. Again, you may be wondering how I knew a c would apply acurrency format, or a d would display the date as it did. Again, viathe docs. See StandardNumeric Format Strings and Dateand Time Format Strings for more information.

The following small ASP.NET Web page demonstrates using the String.Format methodto apply some formatting to various variables.

<script language="C#" runat="server">
  void Page_Load(Object sender, EventArgs e)
  {
     double price = 4.56;
     DateTime rightNow = DateTime.Now;
     int bigNumber = Int32.MaxValue;

     lblPrice.Text = String.Format("{0:c}", price);
     lblTime.Text = String.Format("{0:T}", rightNow);
     lblDate.Text = String.Format("{0:d}", rightNow);
     lblBigInt.Text = String.Format("{0:#,###}", bigNumber);
   }
</script>

<html>
<body>

   The price is: <asp:label runat="server" id="lblPrice" />
   <p>
   The time is: <asp:label runat="server" id="lblTime" />
   <p>
   The date is: <asp:label runat="server" id="lblDate" />
   <p>
   The biggest 32-bit integer is
   <asp:label id="lblBigInt" runat="server" />
</body>
</html>

The output for the above Web page would be:

The price is: $4.56

The time is: 12:14:52 PM

The date is: 1/19/2002

The biggest 32-bit integer is 2,147,483,647

Happy Programming!

Jul 25

I found the most wonderful free calendar control today online for ASP.NET and am usingit in one of my web applications.

RJS PopCalendar is the calendar I ran across. You can read all about it on thisblog. It is fully customizable using CSS and ASP.NET along with Javascript andis a wonderful calendar that looks and works great.

If you’d like to see the main page for the calendar application it can be found atthe following page:
RJSPopCalendar on GotDotNet

Jul 19

There are many out there who do not have direct access to the server their web applicationis running on and as a result are unable to run aspnet_regsql to setup the ASP.NETmembership database for the SQL Membership Provider. Fortunately I ran acrossthis interesting article on the ASP.NET Membership Provider which included the followingfor programmatically setting the SQL database…

3) Do it programmatically: Make a “Setup.aspx” page that uses the System.Web.Managementutility method:
Management.SqlServices.Install(”server”,”USERNAME”, “PASSWORD”, “databasename”, SqlFeatures.All)

This does everything that ASPNET_REGSQL does. You’d think they would make it moreobvious that you can do this, given the large number of sites that are hosted by commercialshared hosting companies, but no, they decided to push ASPNET_REGSQL as if everybodyeverywhere automatically has access to it. Go figure. There is a sample page “SetUpASPNetDatabase.aspx”in the sample solution where you can simply fill in the above parameters in a form,and press a button to set up your database.

This works great for those of us on shared hosting and other areas where we are unableto setup using alternate methods.

The article also included a great overview and tutorial on the ASP.NET MembershipProvider. Code from the article is also available for download both on the originalsite and from my blog.

Integrating Customized Roles, Membership and Profiles in ASP.NET 2.0 by PeterA. Bromberg, Ph.D.
http://www.eggheadcafe.com/articles/20060529.asp

You can download the original Visual Studio 2005 Solution below:

20060529.zip (167.04KB)