Posted in Miscellaneous

Format C# Code in Blogspot post

Steps to format C# code.

1) Copy the C# code and paste it in the C# code formatter(LINK) TextBox.
2) Check the embed stylesheet checkbox.
3) Click on format my code button.
4) Copy the html code which is generated by that link and paste it in your blogspot post in Edit HTML view of  rich textbox.

After formatting C# code, it looks like below.

   1:  using System;
   2:  using System.Data;
   3:  using System.Configuration;
   4:  using System.Data.SqlClient;
   5:   
   6:  /// <summary>
   7:  /// Summary description for DataAccessLayer
   8:  /// </summary>
   9:   
  10:  public class DataAccessLayer
  11:  {
  12:      public static string GetConnectionString()
  13:      {
  14:          return ConfigurationManager.ConnectionStrings["ConnectionString"].
  15:              ConnectionString.ToString();
  16:      }
  17:   
  18:   
  19:      static SqlConnection con;
  20:   
  21:      public static int ExecuteNonQuery
  22:          (string connectionString, CommandType commandType, 
  23:          string commandText, SqlParameter[] parameters)
  24:      {
  25:          try
  26:          {
  27:              con = new SqlConnection(connectionString);
  28:              SqlCommand cmd = new SqlCommand(commandText, con);
  29:              cmd.CommandType = commandType;
  30:              foreach (SqlParameter p in parameters)
  31:              { cmd.Parameters.Add(p); }
  32:              con.Open();
  33:              return cmd.ExecuteNonQuery();
  34:          }
  35:          catch (SqlException ex)
  36:          { throw new ArgumentException(ex.Message); }
  37:          finally { con.Close(); }
  38:      }
  39:   
  40:   
  41:      public static DataSet ExecuteDataSet
  42:          (string connectionString, CommandType commandType, 
  43:          string commandText, SqlParameter[] parameters)
  44:      {
  45:          try
  46:          {
  47:              SqlConnection sqlcon = new SqlConnection(connectionString);
  48:              SqlCommand cmd = new SqlCommand(commandText, sqlcon);
  49:              cmd.CommandType = commandType;
  50:              foreach (SqlParameter p in parameters)
  51:              { cmd.Parameters.Add(p); }
  52:              DataSet ds;
  53:              using (SqlDataAdapter da = new SqlDataAdapter(cmd))
  54:              {
  55:                  ds = new DataSet();
  56:                  da.Fill(ds);
  57:              }
  58:              return ds;
  59:          }
  60:          catch (SqlException ex)
  61:          { throw new ArgumentException(ex.Message); }
  62:      }
  63:   
  64:  }
Link to format C# code is http://www.manoli.net/csharpformat/
Advertisements

One thought on “Format C# Code in Blogspot post

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s