Wednesday, June 29, 2011

Visual Studio List of Some ShortCut Keys

Shortcut
Description
F3
Finds the next occurrence of the previous search text.
F5
Start debugging
F7
Jump to code behind file from .aspx files
F8
Moves the cursor to the next item, such as a task in the Task List window or a search match in the Find Results window. Each time you press F8, you move to the next item in the list.
F9
Toggle breakpoint
F12
Go to definition of identifier under cursor
Ctrl+F5
Start without debugging
Ctrl+F2
Jump to the Navigation Bar (hit TAB to get to the right side)
Ctrl+F3
Find word under cursor
Ctrl+TAB
Toggle between windows in Visual Studio
Ctrl+I
Incremental search (this is way better than Ctrl+F)
Ctrl+J
Force IntelliSense for field members
Ctrl+C (with nothing selected)
Copy whole line
Ctrl+Enter
Open line above line cursor is on
Ctrl-X or Ctrl-L (with nothing selected)
Cut whole line
Ctrl+]
Bounce cursor between matching parentheses/brackets/braces
Ctrl+PageDown
Toggle between Design and Source views in .aspx files
Alt+W, L
Close all windows
Ctrl+K, Ctrl+C
Comment out selection
Ctrl+K, Ctrl+U
Uncomment selection
Ctrl+K, Ctrl+D
Format document
Ctrl+K, Ctrl+X
Insert snippet (or just type in the snippet name and hit TAB, TAB)
Ctrl+K, Ctrl+S
Surround selected lines with snippet
Ctrl+K, Ctrl+K
Toggle bookmark on/off
Ctrl+K, Ctrl+P
Jump to previous bookmark
Ctrl+K, Ctrl+N
Jump to next bookmark
Ctrl+M, Ctrl+M
Open/close current fold
Ctrl+M, Ctrl+O
Fold all methods
Ctrl+R, Ctrl+R
Enables or disables word wrap in an editor.
Ctrl+Shift+B
Build solution
Ctrl+Shift+C
Displays the Class View window
Ctrl+Shift+Enter
Open line below line cursor is on
Ctrl+Shift+F
Global Search
Ctrl+Shift+F9
Delete all breakpoints
Ctrl+Alt+A
Displays the Command window, which allows you to type commands that manipulate the IDE.
Ctrl+Alt+I
Displays the Immediate window, where you can evaluate expressions and execute individual commands.
Ctrl+Alt+K
Displays the Task List window where you customize, categorize and manage tasks, comments, shortcuts, warnings and error messages.
Ctrl+Alt+L
Open the Solution Explorer (to find your file after you just closed them all)
Ctrl+Alt+T
View Document Outline
Ctrl+Alt+0
Displays the Output window to view status messages at run time
Ctrl+Alt+R
Open browser within VS.NET
Ctrl+Alt+U
Displays the Modules window, which allows you to view the .dll or .exe files used by the program. In multiprocess debugging, you can right-click and select Show Modules for all Programs.
Ctrl+Alt+X
Open Toolbox
Shift+Alt+Enter
View editor in full screen mode

SET NOCOUNT (Transact-SQL)



Whenever we write any procedure and execute it a message appears in message

window that shows no of rows affected with the statement written in the procedure

and we become very happy to see that our procedure is working. But do you know

that this message creates an extra overhead on the network? Yes it does.

By removing this extra overhead from the network, we can actually improve the

performance of our database and our application.

How should we do it?

When you create any procedure then first line of your procedure should be

SET NOCOUNT ON;

This one line of code turns off the message that SQL server sends back to front end

after every T-SQL statement is executed. This is applied for all SELECT, INSERT,

UPDATE and DELETE statements. As when stored procedures are executed there is no

need to pass this information back to front end.

When SET NOCOUNT is ON, the count is not returned. When SET NOCOUNT is OFF,

the count is returned.If we still need to get the count of no of rows affected, we can

still use @@ROWCOUNT option. Because The @@ROWCOUNT function is updated even

when SET NOCOUNT is ON.

The setting specified by SET NOCOUNT is in effect at execute or run time and not

at parse time.

Microsoft even realized the issue that this creates and has changed the stored

procedure templates from SQL Server 2000 to SQL Server 2005.

Template used in SQL SERVER 2005

================================================

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

-- =============================================

-- Author:

-- Create date:

-- Description:

-- =============================================

CREATE PROCEDURE

-- Add the parameters for the stored procedure here

<@Param1, sysname, @p1> = ,

<@Param2, sysname, @p2> =

AS

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

SET NOCOUNT ON;

-- Insert statements for procedure here

SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>

END

GO

================================================

Setting SET NOCOUNT to ON can provide a significant performance boost, because network traffic is

greatly reduced.

Tuesday, June 28, 2011

lock computer

Right click desktop-->new-->shortcut-->some window open(appear) --> give to --(Rundll32 User32.dll, LockWorkStation) and then next give any name like (lock computer) -->press ok.--> then double click that icon....then it will automatically lock ur computer........enjoy...by chitharan.s

Asp.net WebService or Creating and Consuming WebService in asp.net or Create and call webservice in asp.net or how to create webservice and how to use webservice in asp.net


Tuesday, May 17, 2011
Introduction:

Here I will explain what webservice is, uses of webservice and how to create webservice and how to consume webservice in asp.net.

Description:
Today I am writing article to explain about webservices. First we will see what is webservice is and uses of webservice and then we will see how to use webservice in our applications.

What is Web Service?

Web Service is an application that is designed to interact directly with other applications over the internet. In simple sense, Web Services are means for interacting with objects over the Internet. The Web serivce consumers are able to invoke method calls on remote objects by using SOAP and HTTP over the Web. WebService is language independent and Web Services communicate by using standard web protocols and data formats, such as
  • HTTP
  • XML
  • SOAP
Advantages of Web Service

Web Service messages are formatted as XML, a standard way for communication between two incompatible system. And this message is sent via HTTP, so that they can reach to any machine on the internet without being blocked by firewall.

Examples for Web Service

Weather Reporting: You can use Weather Reporting web service to display weather information in your personal website.

Stock Quote: You can display latest update of Share market with Stock Quote on your web site.

News Headline: You can display latest news update by using News Headline Web Service in your website.

In summary you can any use any web service which is available to use. You can make your own web service and let others use it. Example you can make Free SMS Sending Service with footer with your advertisement, so whosoever use this service indirectly advertise your company... You can apply your ideas in N no. of ways to take advantage of it.

Frequently used word with web services

What is SOAP?

SOAP (simple object access protocol) is a remote function calls that invokes method and execute them on Remote machine and translate the object communication into XML format. In short, SOAP are way by which method calls are translate into XML format and sent via HTTP.

What is WSDL? 

WSDL stands for Web Service Description Language, a standard by which a web service can tell clients what messages it accepts and which results it will return.
WSDL contains every detail regarding using web service and Method and Properties provided by web service and URLs from which those methods can be accessed and Data Types used.

What is UDDI?

UDDI allows you to find web services by connecting to a directory.

What is Discovery or .Disco Files?

Discovery files are used to group common services together on a web server. Discovery files .Disco and .VsDisco are XML based files that contains link in the form of URLs to resources that provides discovery information for a web service. Disco File contains URL for the WSDL, URL for the documentation and URL to which SOAP messages should be sent.

Before start creating web service first create one table in your database and give name UserInformation in my code I am using same name and enter some dummy data for our testing purpose

Column Name
Data Type
Allow Nulls
UserId
Int(Set Identity=true)
No
UserName
Varchar(50)
Yes
FirstName
Varchar(50)
Yes
LastName
Varchar(50)
Yes
Location
Varchar(50)
Yes

Now we will see how to create new web service application in asp.net

Open visual studio ---> Select File ---> New ---> Web Site ---> select ASP.NET Web Service



Now our new web service ready our webservice website like this



Now open your Service.cs file in web service website to write the code to get the user details from database

Before writing the WebMethod in Service.cs first add following namespaces


using System.Xml;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
After adding namespaces write the following method GetUserDetails in Service.cs page

[WebMethod]
public XmlElement GetUserDetails(string userName)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName like @userName+'%'", con);
cmd.Parameters.AddWithValue("@userName", userName);
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(cmd);
// Create an instance of DataSet.
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
// Return the DataSet as an XmlElement.
XmlDataDocument xmldata = new XmlDataDocument(ds);
XmlElement xmlElement = xmldata.DocumentElement;
return xmlElement;
}

Here we need to remember one point that is adding [WebMethod] before method definition because we need to access web method pulically otherwise it’s not possible to access method publically. If you observe above code I converted dataset to XmlElement t because sometimes we will get error like return type dataset invalid type it must be either an IListSource, IEnumerable, or IDataSource to avoid this error I converted dataset to XmlElement.

Here we need to set the database connection in web.config because here I am getting database connection from web.config


<connectionStrings>
<add name="dbconnection" connectionString="Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB"/>
</connectionStrings>
Now run your web service it would be like this


Our web service is working fine now we need to know how we can use webservice in our application? Before to know about using web service in application first Deploy your webservice application in your local system if you want to know how to deploy application in your local system check this link deploy application in local system

How to Use Web service in web application?

By using this webservice we can get the user details based on username. For that first create one new web application

Open visual studio ---> Select File ---> New ---> Web Site ---> select ASP.NET Web Site


After creation of new website right click on solution explorer and choose “Add web reference” that would be like this


After select Add Web reference option one window will open like this 



Now enter your locally deployed web service link and click Go button after that your web service will found and window will looks like this


 

Now click on Add Reference button web service will add successfully. Now open your Default.aspx page and design like this


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Getting Data from WebService</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<b>Enter UserName:</b>
</td>
<td>
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />
</td>
</tr>
</table>
</div>
<div>
<asp:GridView ID="gvUserDetails" runat="server" EmptyDataText="No Record Found">
<RowStyle BackColor="#EFF3FB" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
</form>
</body>
</html>
Now in code behind add following namespaces

using System.Data;
using System.Xml;


After adding namespaces write the following code in code behind


protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindUserDetails("");
}
}
protected void BindUserDetails(string userName)
{
localhost.Service objUserDetails = new localhost.Service();
DataSet dsresult = new DataSet();
XmlElement exelement = objUserDetails.GetUserDetails(userName);
if(exelement!=null)
{
XmlNodeReader nodereader = new XmlNodeReader(exelement);
dsresult.ReadXml(nodereader, XmlReadMode.Auto);
gvUserDetails.DataSource = dsresult;
gvUserDetails.DataBind();
}
else
{
gvUserDetails.DataSource = null;
gvUserDetails.DataBind();   
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
BindUserDetails(txtUserName.Text);
}
Now run your application and check output