Wednesday, March 18, 2009

some important points for always remmber.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SELECT @@IDENTITY
It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.
@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.
SELECT SCOPE_IDENTITY()
It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.
SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.
SELECT IDENT_CURRENT(’tablename’)
It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.
To avoid the potential problems associated with adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your T SQL Statement or Stored Procedure.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Refresh your page after every 6 second:


[meta http-equiv="refresh" content="6"]
[meta http-equiv="refresh" content="10;URL=Default2.aspx" /]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Find control in master page:: Master.FindControl("lbl")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Load master page dynamicaly::
protected void Page_PreInit(object sender, EventArgs e)
{
this.MasterPageFile = "MasterPage2.master";
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Why only one runat server form only one time in pae

in asp.net page::
1. The form is always submitted to the page itself. If you specify an action attribute, it is ignored. If you omit the method attribute, it will be set to method="post" by default. Also, if you do not specify the name and id attributes, they are automatically assigned by ASP.NET.
If you select view source in an .aspx page containing a form with no name, method, action, or id attribute specified, you will see that ASP.NET has added these attributes to the form. It looks something like this:

...some code


2.All server controls must appear within a

tag, and the tag must contain the runat="server" attribute. The runat="server" attribute indicates that the form should be processed on the server. Eg. If we put a button inside a form tag without runat="server" then its click event give an
Error:'Button' must be placed inside a form tag with runat=server
3. But one can create more then one form tag with runat="server". Using the visible property to set visible one at a time.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Differece Between Cast And Convert::
1. The difference is CAST is more ANSI standard and use this only if you are writing a program which you will need to use in many database platforms. Where CONVERT is Microsoft specific and more powerful.
2. Convert can used to format datatype but Cast can not do so.
SELECT GETDATE() AS UnconvertedDateTime, CAST(GETDATE() AS nvarchar(30)) AS UsingCast, CONVERT(nvarchar(30), GETDATE(), 126) AS UsingConvertTo_ISO8601
3. Cast can be used in the like command.
SELECT p.FirstName, p.LastName, s.SalesYTD, s.SalesPersonID FROM Person.Contact p JOIN Sales.SalesPerson s ON p.ContactID = s.SalesPersonID WHERE CAST(CAST(s.SalesYTD AS int) AS char(20)) LIKE '2%';
4. The CAST function is much better at preserving the decimal places when converting decimal and numeric data types. Most of developers and DBA’s that I have come across prefer to us the CAST function although CONVERT tends to be a bit for useful since it allows you to format the output.

Thanks

Helpondesk Team

No comments: