Friday, July 31, 2009

Finding the nth highest salary of an employee.

Finding the nth highest salary of an

employee.

CREATE TABLE Employee_Test
(
Emp_ID INT Identity,
Emp_name Varchar(100),
Emp_Sal Decimal (10,2)
)

INSERT INTO Employee_Test VALUES ('Anees',1000);
INSERT INTO Employee_Test VALUES ('Rick',1200);
INSERT INTO Employee_Test VALUES ('John',1100);
INSERT INTO Employee_Test VALUES ('Stephen',1300);
INSERT INTO Employee_Test VALUES ('Maria',1400);

--Highest Salary
select max(Emp_Sal) from Employee_Test

--3rd Highest Salary
select min(Emp_Sal) from Employee_Test where
Emp_Sal in
(select distinct top 3
Emp_Sal from Employee_Test order by Emp_Sal desc)

--nth Highest Salary
select min(Emp_Sal) from Employee_Test
where Emp_Sal in
(select distinct top n Emp_Sal from
Employee_Test order by Emp_Sal desc)



Thursday, July 30, 2009

Sql Transaction with stored procedure

create two table first and create stored procedure

create table emp(emp_id int , empname varchar(25));
create proc emp1
@emp_id int ,
@empname varchar(25)
as
begin
insert into emp values(@emp_id,@empname)
end

create table emp_detail (emp_id int ,city varchar(25));
create proc emp2
@emp_id int,
@city varchar(25)
as
begin
insert into emp_detail values (@emp_id,@city)
end

Then write this code
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=.;
initial catalog =abhishek;uid=sa; pwd=computer");
con.Open();
SqlTransaction st;
st = con.BeginTransaction("First");


SqlCommand cmd1 = new SqlCommand();
cmd1.Transaction = st;

try
{

cmd1.Parameters.Add("@emp_id", SqlDbType.Int).Value =
TextBox1.Text;
cmd1.Parameters.Add("@empname", SqlDbType.VarChar, 25).Value =
TextBox2.Text;
cmd1.CommandText = "emp1";
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Connection = con;

cmd1.ExecuteNonQuery();

cmd2 = new SqlCommand();
cmd2.Transaction = st;

cmd2.Parameters.Add("@emp_id", SqlDbType.Int).Value
= TextBox1.Text;
cmd2.Parameters.Add("@city", SqlDbType.VarChar, 25).Value
= TextBox3.Text;
cmd2.Connection = con;

cmd2.CommandText = "emp2";
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.ExecuteNonQuery();
st.Commit();
}
catch(Exception ex)
{
st.Rollback();
Response.Write(ex.Message.ToString());
}
}

Monday, July 27, 2009

http://www.turboupload.com/wm0alrz7s20y/ASP._NET_3._5_Social_Networking~tqw~_darksiderg.pdf.html

Thursday, July 23, 2009

Visual Studio Keyboard Shortcuts

Key Combination Use Description
CTRL+ALT+L View Solution Explorer Use Auto Hide for all tool windows to maximize screen real estate. Whenever you need to open the Solution Explorer, it’s just a shortcut away.
CTRL+ALT+X View ToolBox .
CTRL+ALT+O View Output .
CTRL+\, then press E View Error List .
CTRL+\, then press T View Task List .
F4 View Property Window Select the control, then press F4 to view property window.
CTRL+PgDn or CTRL+PgUp Design View to Source View and vice-versa Toggle between design and source view in HTML editor.
SHIFT+F7 Design View to Source View and vice-versa Toggle between design and source view in HTML editor.
F7 Design or Source View to Code View Toggle from designer view to code view.
SHIFT+F7 Code View to Design View Toggle from code view to designer view.
F5 Start Debugging .
CTRL+F5 Start Without Debugging .
F10 Debug Step over
F11 Debug Step into
SHIFT+F11 Debug Step out
CTRL+F10 Debug Run to cursor
F9 Toggle Breakpoint .
CTRL+M, then press O Collapse to Definitions. .
CTRL+K, then CTRL+C Comment selected Block .
CTRL+K, then CTRL+U Uncomment selected block .
CTRL+- Go back to the previous location in the navigation history .
F6 Build Solution .
SHIFT+F6 Build Website .
ATL+B, then R Rebuild Solution .
CTRL+L Deletes Entire Line .
CTRL+G GO to the Line Number .
SHIFT+ATL+Enter Toggle Full Screen Mode .
CTRL+Space Invoke the Intellisense List Invokes the intellisence list where cursor pointed.

Saturday, July 18, 2009

SQLSERVER .NET Integration Questions

What are steps to load a .NET code in SQL SERVER 2005?
How can we drop a assembly from SQL SERVER?
Are changes made to assembly updated automatically in database?
Why do we need to drop assembly for updating changes?
How to see assemblies loaded in SQL Server?
I want to see which files are linked with which assemblies?
Does .NET CLR and SQL SERVER run in different process?
Does .NET controls SQL SERVER or is it vice-versa?
Is SQLCLR configured by default?
How to configure CLR for SQL SERVER?
Is .NET feature loaded by default in SQL Server?
How does SQL Server control .NET run-time?
What’s a “SAND BOX” in SQL Server 2005?
What is a application domain?
How are .NET Appdomain allocated in SQL SERVER 2005?
What is Syntax for creating a new assembly in SQL Server 2005?
Do Assemblies loaded in database need actual .NET DLL?
Does SQL Server handle unmanaged resources?
What is Multi-tasking ?
What is Multi-threading ?
What is a Thread ?
Can we have multiple threads in one App domain ?
What is Non-preemptive threading?
What is pre-emptive threading?
Can you explain threading model in SQL Server?
How does .NET and SQL Server thread work?
How are exception in SQLCLR code handled?
Are all .NET libraries allowed in SQL Server?
What is “Hostprotectionattribute” in SQL Server 2005?
How many types of permission level are there for an assembly?
Can you name system tables for .NET assemblies?
Are two version of same assembly allowed in SQL Server?
How are changes made in assembly replicated?
Is it a good practice to drop a assembly for changes?
In one of the projects following steps where done, will it work?
What does Alter assembly with unchecked data signify?
How do I drop an assembly?
Can we creat SQLCLR using .NET framework 1.0?
While creating .NET UDF what checks should be done?
How do you define a function from the .NET assembly?
Can compare between T-SQL and SQLCLR ?
With respect to .NET is SQL SERVER case sensitive?
Does case sensitive rule apply for VB.NET?
Can nested classes be accessed in T-SQL?
Can we have SQLCLR procedure input as array?
Can object datatype be used in SQLCLR?
How’s precision handled for decimal datatypes in .NET?
How do we define INPUT and OUTPUT parameters in SQLCLR?
Is it good to use .NET datatypes in SQLCLR?
How to move values from SQL to .NET datatypes?
What is System.Data.SqlServer?
What is SQLContext?
Can you explain essential steps to deploy SQLCLR?
How do create function in SQL Server using .NET?
How do we create trigger using .NET?
How to create User Define Functions using .NET?
How to create User Defined Create aggregates using .NET?
What is Asynchronous support in ADO.NET?
What is MARS support in ADO.NET?
What is SQLbulkcopy object in ADO.NET ?
How to select range of rows using ADO.NET?

ASP .Net interview Questions

Tough ASP.NET interview questions
Describe the difference between a Thread and a Process?
What is a Windows Service and how does its lifecycle differ from a .standard. EXE?
What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memory for the system? How would this affect a system design?
What is the difference between an EXE and a DLL?
What is strong-typing versus weak-typing? Which is preferred? Why?
What.s wrong with a line like this? DateTime.Parse(myString
What are PDBs? Where must they be located for debugging to work?
What is cyclomatic complexity and why is it important?
Write a standard lock() plus double check to create a critical section around a variable access.
What is FullTrust? Do GAC’ed assemblies have FullTrust?
What benefit does your code receive if you decorate it with attributes demanding specific Security permissions?
What does this do? gacutil /l | find /i “about”
What does this do? sn -t foo.dll
What ports must be open for DCOM over a firewall? What is the purpose of Port 135?
Contrast OOP and SOA. What are tenets of each
How does the XmlSerializer work? What ACL permissions does a process using it require?
Why is catch(Exception) almost always a bad idea?
What is the difference between Debug.Write and Trace.Write? When should each be used?
What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?
Does JITting occur per-assembly or per-method? How does this affect the working set?
Contrast the use of an abstract base class against an interface?
What is the difference between a.Equals(b) and a == b?
In the context of a comparison, what is object identity versus object equivalence?
How would one do a deep copy in .NET?
Explain current thinking around IClonable.
What is boxing?
Is string a value type or a reference type?

ADO.NET Interview Questions

What is the namespace in which .NET has the data functionality classes ?
Can you give a overview of ADO.NET architecture ?
What are the two fundamental objects in ADO.NET ?
What is difference between dataset and datareader ?
What are major difference between classic ADO and ADO.NET ?
What is the use of connection object ?
What is the use of command objects and what are the methods provided by the command object ?
What is the use of dataadapter ?
What are basic methods of Dataadapter ?
What is Dataset object?
What are the various objects in Dataset ?
How can we connect to Microsoft Access , Foxpro , Oracle etc ?
How do we connect to SQL SERVER , which namespace do we use ?
How do we use stored procedure in ADO.NET and how do we provide parameters to the stored procedures?
How can we force the connection object to close after my datareader is closed ?
I want to force the datareader to return only schema of the datastore rather than data ?
How can we fine tune the command object when we are expecting a single row or a single value ?
Which is the best place to store connectionstring in .NET projects ?
What are steps involved to fill a dataset ?(Twist :- How can we use dataadapter to fill a dataset ?)
What are the various methods provided by the dataset object to generate XML?
How can we save all data from dataset ?
How can we check that some changes have been made to dataset since it was loaded ?(Twist :- How can cancel all changes done in dataset ? ,How do we get changed value dataset ? )
How add/remove row’s in “DataTable” object of “DataSet” ?
What’s basic use of “DataView” ?
What’s difference between “DataSet” and “DataReader” ?
How can we load multiple tables in a DataSet ?
How can we add relation’s between table in a DataSet ?
What’s the use of CommandBuilder ?
What’s difference between “Optimistic” and “Pessimistic” locking ?
How many way’s are there to implement locking in ADO.NET ?
How can we perform transactions in .NET?
What’s difference between Dataset. clone and Dataset. copy ?

HTML Interview Questions

How to create links to sections on the same page in HTML.
How do I create forums for my webpage?
How can I get more traffic or people to visit my website?
How can I check if anyone is stealing my website content?
How can I get more visitors on my forum?
Creating a web page with a single background image not a tiled background.
Opening new web page window when clicking on a link.
Creating a new window in HTML for a single image.
Creating multicolor links in HTML.
How to create a fixed background image on a web page.
How to create a counter on your web page.
How to resize an image with HTML.
Getting subject added to the mailto command.
How can I copyright or otherwise protect my images online?
After uploading an update to my webpage it looks the same.
Internet Explorer error: Done, but with errors on page.
How do I indent text on my web page or in HTML?
Why does alt text in the html img tag not work in Firefox?
Forum If your question is not listed on this page please try our online forum.
How do I view the source code of a web page?
Creating a mail link on a web page.
Creating flashing background when opening a web page.
Linking an image to another page in HTML.
Creating images as links with no borders.
Allowing user to choose their background color.
Creating a HTML text field bigger then one line.
What is HTML?
Creating unformatted HTML text.
Transferring user to new web page automatically.
Creating three images: first on left, second centered, third on right.
Defining the background and text color.
Is it possible to make the HTML source not viewable?
Creating images that are right aligned with the web page window.
Creating an image with a text description in HTML.
Creating a link to play a sound file in HTML.
Changing the type of font displayed on web page.
How to create a link to automatically run .exe file once downloaded.
Creating a link without an underline in HTML.
Changing link color when moving mouse over link in HTML.
Creating HTML push button link.
Creating simple search for your web page.
Creating an Onmouse over for images in HTML.
Creating script to break web page out of frames.
Accepting credit card on web page.
How do I close a browser window with HTML code?
Creating a HTML back button.
Information about favicon.ico.
How can I insert a movie into a HTML document?
How do I make money on my website?
How to create a guestbook on your web page.
How can I copy something from a webpage to my webpage?

Tuesday, July 7, 2009

Gridview With DropdownList Update



<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
onrowdatabound="GridView1_RowDataBound"
onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="Edit"
ShowHeader="false">
<ItemTemplate>
<asp:LinkButton ID="btnedit"
runat="server"
CommandName="Edit" Text="Edit" ></asp:
LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnupdate" runat="server"
CommandName="Update" Text="Update"
></asp:LinkButton>
<asp:LinkButton ID="btncancel" runat="server"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="id">
<ItemTemplate>
<asp:Label ID="id" runat="server"
Text='<%#Eval("id") %
>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>
<asp:TemplateField HeaderText="city">
<ItemTemplate>
<asp:Label ID="city" runat="server"
Text='<%#Eval("city")
%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="dropcity" runat="server"></
asp:DropDownList>
<asp:RequiredFieldValidator ID="vali" runat="server"
ControlToValidate="dropcity"
ErrorMessage="*"><
/asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>

</Columns>

</asp:GridView>



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace dropdownwithgrid
{
public partial class _Default : System.Web.UI.Page
{
SqlConnection sqlcon = new SqlConnection("Data Source=.;
Initial Catalog=abhishek;Persist Security Info=True;User ID=sa;
Password=sa");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
binddata();

}
}

public void binddata()
{
DataTable dt = new DataTable();

sqlcon.Open();
SqlDataAdapter sda = new SqlDataAdapter();
string strQuery = "select id,city from id ";
SqlCommand cmd = new SqlCommand(strQuery);
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlcon;
sda.SelectCommand = cmd;
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
sqlcon.Close();
}

protected void GridView1_RowUpdating(object sender,
GridViewUpdateEventArgs e)
{
Label l1 = (Label)GridView1.Rows[e.RowIndex].FindControl("id");
DropDownList d1 = (DropDownList)GridView1.Rows[e.RowIndex].
FindControl("dropcity");
sqlcon.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlcon;
cmd.CommandText = "update id set city='" +
d1.SelectedValue.ToString() + "' where id='" + l1.Text + "'";
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
binddata();
}

protected void GridView1_RowEditing(object sender,
GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
binddata();

}
public DataTable load_City()
{
// sqlcon.Open();
DataTable dt = new DataTable();


string sql = "select city from id";
SqlCommand cmd = new SqlCommand(sql);
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlcon;
SqlDataAdapter sd = new SqlDataAdapter(cmd);
sd.Fill(dt);

return dt;


}
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
DataRowView drv = e.Row.DataItem as DataRowView;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
DropDownList dp = (DropDownList)e.Row.FindControl("dropcity");
DataTable dt = load_City();
for (int i = 0; i < dt.Rows.Count; i++)
{
ListItem lt = new ListItem();
lt.Text = dt.Rows[i][0].ToString();
dp.Items.Add(lt);
}
dp.SelectedValue = drv[1].ToString();
}
}

}
}
}

Friday, July 3, 2009

Paging in Detail View

 <asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False"

DataKeyNames="EmployeeID"
DataSourceID="SqlDataSource1" Height="50px"

Width="125px" AllowPaging="true">

<Fields>
<asp:BoundField DataField="EmployeeID"
HeaderText="EmployeeID"

InsertVisible="False" ReadOnly="True"
SortExpression="EmployeeID" />

<asp:BoundField DataField="LastName"
HeaderText="LastName"

SortExpression="LastName" />
<asp:BoundField DataField="FirstName"
HeaderText="FirstName"

SortExpression="FirstName" />
<asp:BoundField DataField="Title" HeaderText="Title"
SortExpression="Title"
/>

<asp:BoundField DataField="TitleOfCourtesy"
HeaderText="TitleOfCourtesy"

SortExpression="TitleOfCourtesy" />
<asp:BoundField DataField="BirthDate"
HeaderText="BirthDate"

SortExpression="BirthDate" />
</Fields>
<PagerSettings Mode="NextPreviousFirstLast"
FirstPageText="[First Page]"
LastPageText="[LastPage]"
PreviousPageText="[PreviousPage]"
NextPageText="[NextPage]" />
</asp:DetailsView>
<br />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<
%$ ConnectionStrings:NorthwindConnectionString %>"

SelectCommand="SELECT [EmployeeID],
[LastName], [FirstName], [Title],
[TitleOfCourtesy], [BirthDate] FROM [Employees]">

</asp:SqlDataSource>