Google Analytics Alternative

Search This Blog

Thursday, October 25, 2012

EntityFramework inner join

Column concatenation using Linq to EntityFramework.
here we have one simple example where there are two tables.
Employee with following fileds

CREATE TABLE [dbo].[empMaster](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Age] [int] NULL,
[IsActive] [bit] NULL CONSTRAINT [DF_empMaster_IsActive]  DEFAULT ((1)),
[CreatedDate] [datetime] NULL CONSTRAINT [DF_empMaster_CreatedDate]  DEFAULT (getdate()),
[Id] ASC

and another table is with

CREATE TABLE [dbo].[employee](
[id] [int] IDENTITY(1,1) NOT NULL,
[Salary] [int] NULL,
[id] ASC

Now i want to get name of employee and salary of that employee.
so i used innerjoin like this

from empMaster em
inner join employee e
Result of inner join.

but in Linq To EntityFrame work it works like this.

   var outputvalue = (from emp in obj.empMasters 
                                      join e in obj.employees on emp.Id equals
                                     select new {
                                     }).ToList().Select(q =>new {Id = q.Id,Name = q.Name,dummyValue = q.Id.ToString() + " " + 


Tuesday, October 16, 2012

Prepare DTO layer by using below script

Declare @sql nvarchar(MAX)
Declare @TmpTable table (ID int Identity(1,1), c_Column_name varchar(500),c_Data_type varchar(50),c_character_Maximum_length nvarchar(50))

Insert into @TmpTable (c_Column_name,c_Data_type,c_character_Maximum_length)
WHERE TABLE_NAME = 'TT_M_User'  --Table Name
set @CurID = 1
set @sql=''
SELECT @MaxID=Max(ID) FROM @TmpTable WHILE @MaxID >=@CurID BEGIN -- Logic to be performed
select @sql = @sql + char(13)+ ' public ' +
    case c_Data_type
    when 'varchar' then ' string '
    when 'nvarchar' then ' string '
    when 'bit' then ' bool '
    when 'datetime' then ' DateTime '
    when 'binary' then ' Byte[] '
    else c_Data_type end + ' ' + c_Column_Name + ' {get;set;} '
from @TmpTable where ID=@CurID
set @CurID = @CurID +1
print @sql

Thursday, May 24, 2012

Find job by jobberclub

Now it is too easy to find job for freshers to experts.

just visit this below link now. and search your desire profile job.

I hope it will help you.

Tuesday, May 1, 2012

Three simple character that is important in every once life.
G : Generator
O : Operator
D : Destroyer

God is Generator of life.
God is Operator of life.
and finally
God is Destroyer of life.


Saturday, April 7, 2012

ASP.NET : Difference between Server.Transfer and response.Redirect

Response.Redirect sends message to the browser saying it to move to some different page, while server.transfer does not send any message to the browser but rather redirects the user directly from the server itself. So in server.transfer there is no round trip while response.redirect has a round trip and hence puts a load on server.

Using Server.Transfer you can not redirect to a different from the server itself. Example if your server is you can use server.transfer to move to but yes you can move to, i.e. within websites. This cross server redirect is possible only using Response.redirect.

With server.transfer you can preserve your information. It has a parameter called as “preserveForm”. So the existing query string etc. will be able in the calling page.

Use server.transfer to navigate within website. And use Response.redirect to redirect to another website.

You can transfer current users page request to another page with two methods:

    * Server.Transfer (HttpServerUtility.Transfer Method)
    * Response.Redirect (HttpResponse.Redirect Method)

Its not always clear how these two approaches differ so let us try to clarify things a little:

Response.Redirect sends HTTP code 302 down to the users browser along with the new URL location of the wanted page. 
HTTP Code 302 actually means ' The requested resource resides temporarily under a different URI'.
After browser receives this code it tries to open the new location of the resource that was suggested by the server.
This actually causes two requests to the server, first one to the original URL, and second to the new URL that is suggested via 302 response.
All the Query Strings and Form variables are lost during the redirect and they are not available to the redirected URL.

Also its important to say that the new URL can reside on the same server but also it can be on some other server and the redirected URL does not need to be .aspx page it can be regular HTML page also).

So we can us the Redirect method to redirect users request to another page on our server like this:


or to redirect our it to some other server like this:


In contrast to all this when we call Server.Transfer we do not initiate another request to the server, but the original request is simply rewritten and transfered to some other page on the same server.
(This off course means that we can use it only to transfer requests to the pages on the same server, not to some other servers and we can only transfer to .aspx pages and not other page types like HTML, php etc). 

All posted Form variables and query strings can optionally remain available to the second Page where we transfered request (if we use second overload Server.Transfer(string pathbool preserveForm) and supply true for the second parameter).
Otherwise the Form Variables and Query String are cleared just like when we use Redirect.
WARNING: If you use this method to preserve Query String and Form variables and receive error: "View State Is Invalid" its because your EnableViewStateMac attribute of the <pages> element is set to true. More on this error on this page: PRB: "View State Is Invalid" Error Message When You Use Server.Transfer

Its also important to note that because of the way Server.Transfer works, after the transfer, the URL shown in the users Web Browser remains the original one that was requested, because browser has no knowledge that its request was transfered (transfer occurs on the server side).
TIP: One thing to be careful about when using the Server.Transfer is to clear the the HttpResponse object withResponse.Clear method on the transfered page to avoid any output from the first page to be shown on the second page.

So now that we know what are the similarities and differences between these two approaches we can try to use them wisely.

Here is the summary:

Response.Redirect should be used when:
  • we want to redirect the request to some plain HTML pages on our server or to some other web server
  • we don't care about causing additional roundtrips to the server on each request
  • we do not need to preserve Query String and Form Variables from the original request
  • we want our users to be able to see the new redirected URL where he is redirected in his browser (and be able to bookmark it if its necessary)
Server.Transfer should be used when:
  • we want to transfer current page request to another .aspx page on the same server
  • we want to preserve server resources and avoid the unnecessary roundtrips to the server
  • we want to preserve Query String and Form Variables (optionally)
  • we don't need to show the real URL where we redirected the request in the users Web Browser

Thursday, March 29, 2012



Which command is used reseed the identity value?


DBCC CHECKIDENT can be used to manually set a new current identity value for the identity column.
DBCC CHECKIDENT ("Sales.ProductType", RESEED, 10);

Sunday, March 4, 2012

Quickest way to SELECT All Columns from a Table

Suppose you have a huge table which has say 30-40 columns and you want to select all of them or most of them say around 30 columns. It is a tedious job to type each of the column names. Here is a quick way to get a comma separated list of all the columns with minimal effort.
  1. Go to SSMS, Open a new query window, Type SELECT followed by a space
  2. Go to Object Explorer
  3. Expand the databases node, expand the user database which contains your table, expand the Tables folder, Expand the Table from which you need to selec the Columns/Data.
  4. Click on "Columns" folder, hold it, and drag it on to the Query Surface after the "SELECT " (Step 1). This place all the columns on to the query surface in a comma separated fashion.
  5. Remove the unwanted columns
  6. Now type in " FROM TableName" at the end of the column list (Outcome of Step 4 & 5) and do the necessary formatting.
It is as simple as that ! This can save a lot of effort required to manually type in the Column Names.

Saturday, February 25, 2012

Find Excel Workbook available sheet name using c#

hi friends, today morning i find one issues to find available sheet in Excel workbook..
so here is solution for this.

first of all we has to upload that file to server [excel] folder and then read excel sheet with oledb provider.
1. create aspx page with having two controls

  •      File upload controls with name [flUpldExcel]
  •      One command button to perform action. 
than once we save excel sheet to server so next step is to find available sheet in work book.
Now want to find available sheets on workbook. for that i write code that will find all sheets.

Code for saving file on server

            string strFilePath = Server.MapPath("excel") + @"\";
            string strFileName = string.Empty;
            if (flUpldExcel.HasFile)
                strFileName = flUpldExcel.PostedFile.FileName;
                flUpldExcel.SaveAs(strFilePath + strFileName);
                string[] strSheetName;
                strSheetName = GetExcelSheetNames(strFilePath + strFileName);
                foreach (string item in strSheetName)
                    Response.Write(item + "<br>");
        catch (Exception ex)
            throw ex;

2. Code for find Sheet on excel workbook

 private String[] GetExcelSheetNames(string excelFile)
        OleDbConnection objConn = null;
        System.Data.DataTable dt = null;

            // Connection String. Change the excel file to the file you
            // will search.
            String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
              "Data Source=" + excelFile + ";Extended Properties=Excel 8.0;";
            // Create connection object by using the preceding connection string.
            objConn = new OleDbConnection(connString);
            // Open connection with the database.
            // Get the data table containg the schema guid.
            dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

            if (dt == null)
                return null;

            String[] excelSheets = new String[dt.Rows.Count];
            int i = 0;

            // Add the sheet name to the string array.
            foreach (DataRow row in dt.Rows)
                excelSheets[i] = row["TABLE_NAME"].ToString();

            // Loop through all of the sheets if you want too...
            for (int j = 0; j < excelSheets.Length; j++)
                // Query each excel sheet.

            return excelSheets;
        catch (Exception ex)
            return null;
            // Clean up.
            if (objConn != null)
            if (dt != null)

Note: Excel file should be in Excel 2003 file format.