Monday, June 25, 2012

Using where Condition in Linq in .net

where Condition in Linq in .net / where Condition in Linq in asp.net / how to use where Condition in Linq in .net

var getdata = from ud in objEntity.tblUserDetails
                          where (ud.UId== objudetails.UId)
                          select ud;

Using order by in Linq query in .net


var objSelfJoin = from t1 in objLinq.tblEmps
                             join  t2 in objLinq.tblEmps on t1.EId equals t2.SupervisorId orderby t1.Age                             select new { t1.Full_Name,t1.Age,t1.Salary
};

Using Join query in Linq in .net


var objSelfJoin = from t1 in objLinq.tblEmps
                join t2 in objLinq.tblEmps on t1.EId equals  t2.SupervisorId select new { t1.Full_Name,t1.Age,t1.Salary };

Difference between static variable and constant in c#?


Static Variables:
1.These are Initialized on constructors. 
2.These are Can be assigned for reference types.
3.These Variables set at run time.
Constants:
1.Constants Variable set at compile time itself.
2.Constants must be initialized at declaration time.
3.Constants Assigned for value types only.
4.Constants only primitive data types.

Thursday, June 21, 2012

Error while using group by clause

Column 'tblSales.Salary' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

select ts.SalesmenName,ts.Age,sum(tp.Quantity) as Quantity
from tblSales ts
inner join tblProduct tp on ts.SId=tp.SId
group by tp.SId,ts.SalesmenName,ts.Age


Output :
SalesmenName        Age   Quantity 
 Rajesh             26      3
 Mohan              24      2

Saturday, June 2, 2012

Cross Page Posting In asp.net



ASP.NET by default, submits the form to the same page. Cross page posting is submitting the form to a different page. This is usually required when you are creating a multi page form to collect information from the user on each page. When moving from the source to the target page, the values of controls in the source page can be accessed in the target page.

To use cross-page posting, you have to use the PostBackURL attribute to specify the page we want to post to.

1st Page :

<asp:Button ID="btnCrosspage" runat="server" PostBackUrl="~/Default2.aspx" Text="Target Page" />

2nd Page :

protected void Page_Load(object sender, EventArgs e)

{

  if (Page.PreviousPage != null)
  {

   TextBox txtNoOfDays=(TextBox) PreviousPage.FindControl("txtNoOfDays");
  }

Difference between Response.output.write() and Response.write() ?


Response.write() : just writes/displays the text or string on the web page. 
Response.output.write() :
formats the string in the format specified before displaying it on the web page .

Response.Write("Current Date Time is "+DateTime.Now.ToString());

Response.Output.Write("{0:d}", "Current Date Time: ", DateTime.Now)
The index {0} is replaced by "Current Date Time:"


What is the base class of .NET?
System.Object is the base class of .NET.

Apply Themes to an entire application



How Can you apply Themes to an entire application?
By specifying the theme in the web.config file.
Ex:
<configuration>
<system.web>
<pages theme="BlueMoon" />
</system.web>
</configuration>


How do you exclude an ASP.NET page from using Themes?
To remove themes from your page, use the EnableTheming attribute of the Page directive.


Page Level :
<%@ Page Language="C#" EnableTheming="false" Theme="Theme1" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

Control Level:

<asp:TextBox ID="txtFirstName" EnableTheming="false" runat="server"></asp:TextBox>

Change a Master Page dynamically at runtime


How Can We change a Master Page dynamically at runtime?

To change a master page, set the MasterPageFile property to point to the .master page during the PreInit page event.

Protected by Copyscape Plagiarism Software