Posts

Showing posts from March, 2013

Pivot table in sql Server

A Pivot Table can automatically sort, count, and total the data stored in one table or spreadsheet and create a second table displaying the summarized data. The PIVOT operator turns the values of a specified column into column names, effectively rotating a table. You can use the PIVOT and UNPIVOT relational operators to change a table-valued expression into another table. PIVOT rotates a table-valued expression by turning the unique values from one column in the expression into multiple columns in the output, and performs aggregations where they are required on any remaining column values that are wanted in the final output.  UNPIVOT performs the opposite operation to PIVOT by rotating columns of a table-valued expression into column values. But we will see UNPIVOT afterwords. Example : Table Design : VendorId         nvarchar(50) IncomeDay nvarchar(50) IncomeAmount int Insert Some Data : insert into testdb1.dbo.DailyIncome values ('Nihar', &

How to retrieve last 6 months data in sql server

How to retrieve last n months data in sql server ? Query :   SELECT *   FROM [db1].[dbo].[Data]   where  entry_date >= dateadd(mm,datediff(mm,0,getdate())- 6 ,0) Parameter :  Pink color marked data object worked as n number of months . Output : Display last 6 months data from current date.

How to retrieve Year / Month from Current or Any Datetime in SQL Server

Session 2 : How to retrieve Year / Month from Current or Any Datetime ? select  [YEAR] = YEAR(getdate()) ,[YEAR] = DATEPART(YY,getdate())  ,[MONTH] = month(getdate()) ,[MONTH] = DATEPART(mm,getdate()) ,[MONTH NAME] = DATENAME(mm, getdate()) Output : - YEAR YEAR MONTH    MONTH MONTH NAME 2013 2013 3            3                 March

System operations in C#

          System.Diagnostics.Process The  Process  class provides functionality to monitor system processes across the network, and to start and stop local system processes. In additional to retrieving lists of running processes (by specifying either the computer, the process name, or the process ID) or viewing information about the process that currently has access to the processor, you can get detailed knowledge of process threads and modules both through the  Process  class itself, and by interacting with the ProcessThread  and  ProcessModule  classes. The  ProcessStartInfo  class enables you to specify a variety of elements with which to start a new process, such as input, output, and error streams, working directories, and command line verbs and arguments. These give you fine control over the behavior of your processes. Other related classes let you specify window styles, process and thread priorities, and interact with collections of threads and modules. Some relat

ObjectDataSource in asp.net

Image
ASP.NET 2.0 ships with five built-in data source controls –  SqlDataSource ,  AccessDataSource ,  ObjectDataSource ,  XmlDataSource , and  SiteMapDataSource  – although you can build your own  custom data source controls , if needed. Since we have developed an architecture for our tutorial application, we'll be using the ObjectDataSource against our BLL classes. Step 1: Adding and Configuring the ObjectDataSource Control Start by opening the  SimpleDisplay.aspx  page in the  BasicReporting  folder, switch to Design view, and then drag an ObjectDataSource control from the Toolbox onto the page's design surface. The ObjectDataSource appears as a gray box on the design surface because it does not produce any markup; it simply accesses data by invoking a method from a specified object. The data returned by an ObjectDataSource can be displayed by a data Web control, such as the GridView, DetailsView, FormView, and so on. Note    Alternatively, you may first add the data

User control in asp.net with Example

User control is powerful functionality of ASP.NET. With the help of the user control you can reuse the Design as well as code in the application. Developing User control is similar to developing form in ASP.NET. User control is created in markup file with .ascx extension. We create two user control one for collect the user information and second for Display the user information. Step 1:   Add the Web user control in your form with the name MyControl.ascx ( .ascx is extension for user-control) ASCX code : <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyControl.ascx.cs" Inherits="UserControlDemo.MyControl" %> <asp:TextBox ID="textNumber" runat="server"      ReadOnly="True" Width="32px" Enabled="False" /> <asp:Button Font-Bold="True" ID="buttonUp" runat="server"       Text="^" OnClick="buttonUp_Cl

NameValueCollection with Example in C#

NameValueCollection collection is based on the  NameObjectCollectionBase  class. However, unlike the NameObjectCollectionBase, this class stores multiple string values under a single key. This class can be used for headers, query strings and form data. Each element is a key/value pair. Collections of this type do not preserve the ordering of element, and no particular ordering is guaranteed when enumerating the collection. The capacity of a  NameValueCollection  is the number of elements the  NameValueCollection  can hold. As elements are added to a  NameValueCollection , the capacity is automatically increased as required through reallocation. Aspx :     <table width="100%">         <tr>             <td align ="center">                 <table width ="50%">                     <tr>                         <td>                             <asp:Label ID="Label1" runat="server"

File uploading and Downloading in asp.net

Here we are performing operations like " File Uploading and Downloading From Gridview ". Table Structure : ColumnName   Datatype id           int f_name   nvarchar(50) fileSize           int attachment   varbinary(MAX) contentType   nvarchar(MAX) ASPX Code:      <table width="100%">             <tr>                 <td align="center">                     <table width="50%">                         <tr>                             <td>                                 <asp:Label ID="Label3" runat="server" Text="Select"></asp:Label>                             </td>                             <td>                                 <asp:FileUpload ID="FileUpload1" runat="server" />                             </td>                         </tr>                         <tr>      

File operations in C# (.net)

Here we are performing some basic file operations which widely needed in applications. ASPX :     <div>         <asp:Button ID="Button1" runat="server" Text="CLick" onclick="Button1_Click" />         <asp:FileUpload ID="FileUpload1" runat="server" /><br /><br />          </div> C# :        using System.IO;        using System.Text;         protected void Button1_Click(object sender, EventArgs e)         {             string path = @"E:\MVC Application Demos\ABC.txt";            // File Path taken             string name = FileUpload1.FileName.ToString();                // Here we get File Name only             string path1 = FileUpload1.PostedFile.FileName.ToString();    // Here we get File Path only             if (File.Exists(path.ToString()))             {                      //     ClientScript.RegisterStartupScript(this.GetType(), "myalert"

Stopwatch in c#

Stopwatch  measures time elapsed. It is useful for micro-benchmarks in code optimization. It can perform routine and continuous performance monitoring. The Stopwatch type, found in System.Diagnostics, is useful in many contexts. Example First, Stopwatch is a class in the .NET Framework that is ideal for timing any operation in your C# programs. You must create Stopwatch as an instance. This makes it useful in multi-threaded applications or websites. Program that uses Stopwatch [C#] using System; using System.Diagnostics; using System.Threading; class Program { static void Main() { // Create new stopwatch Stopwatch stopwatch = new Stopwatch (); // Begin timing stopwatch.Start(); // Do something for (int i = 0; i < 1000; i++) { Thread.Sleep(1); } // Stop timing stopwatch.Stop(); // Write result Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed); } } Output Time elapsed: 00:00:01.0001477 Ref: MSDN : Stopwatch