Tuesday, September 4, 2012

Sql Triggers

As a simple definition we can say that
" A trigger is a database object that is attached to a table"

Triggers is  only fired when an INSERT, UPDATE or DELETE occurs in any Data base table.We specify the action to fired the trigger. As per example.

SET NOCOUNT ON

CREATE TABLE Student (St_ID int IDENTITY, St_Desc varchar(10))
go
CREATE TRIGGER tr_Source_INSERT
ON Student
FOR INSERT
AS
PRINT GETDATE()
go
INSERT Student (St_Desc) VALUES ('Test 1')

-- Results --

Apr 28 2001  9:56AM
 
Another example of triggers will be clear the idea.
 
CREATE TABLE Orders (Ord_ID int IDENTITY, Ord_Priority varchar(10))
go
CREATE TRIGGER tr_Orders_INSERT
ON Orders
FOR INSERT
AS
IF (SELECT COUNT(*) FROM inserted WHERE Ord_Priority = 'High') = 1
 BEGIN
  PRINT 'Email Code Goes Here'
 END
go
INSERT Orders (Ord_Priority) VALUES ('High')

-- Results --

Email Code Goes Here 

Triggers make use of two special tables called inserted and deleted.
 The inserted table contains the data referenced in an INSERT before it 
is actually committed to the database. The deleted table contains the 
data in the underlying table referenced in a DELETE before it is 
actually removed from the database. When an UPDATE is issued both tables
 are used. More specifically, the new data referenced in the UPDATE statement is contained in inserted and the data that is being updated is contained in deleted.

Sunday, November 13, 2011

Different Test Style By Java Script.

Hi,
Java script provide different in built function for editing the output of Test Format like.
<html>
<body>

<script type="text/javascript">

var txt = "Hello World!";

document.write("<p>Big: " + txt.big() + "</p>");
document.write("<p>Small: " + txt.small() + "</p>");

document.write("<p>Bold: " + txt.bold() + "</p>");
document.write("<p>Italic: " + txt.italics() + "</p>");

document.write("<p>Fixed: " + txt.fixed() + "</p>");
document.write("<p>Strike: " + txt.strike() + "</p>");

document.write("<p>Fontcolor: " + txt.fontcolor("green") + "</p>");
document.write("<p>Fontsize: " + txt.fontsize(6) + "</p>");

document.write("<p>Subscript: " + txt.sub() + "</p>");
document.write("<p>Superscript: " + txt.sup() + "</p>");

document.write("<p>Link: " + txt.link("http://www.w3schools.com") + "</p>");

document.write("<p>Blink: " + txt.blink() + " (does not work in IE, Chrome, or Safari)</p>");

</script>

</body>
</html>

Just try this and I hope you will got some new.

Wednesday, November 9, 2011

How to convert Xml in to Html (xHtml)

Hi today i got the idea how we can convert our xml page in to xhtml . Its quit simple as just like  css style sheet is uses to decorate html page.
The major different in the process just here we are use xsl (xml style sheet ) instead css. This can be done by the help of  Xslt (xml style sheet transformation ).
Here i am post the example (Its a xml page where we give href relation with xsl plae like.

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
</catalog>
And the code of  cdcatalog.xsl is here
<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th>Title</th>
      <th>Artist</th>
    </tr>
    <xsl:for-each select="catalog/cd">
    <tr>
      <td><xsl:value-of select="title"/></td>
      <td><xsl:value-of select="artist"/></td>
    </tr>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>
The reference of style sheet already given in the top header of xml page.

 <xsl:template match="/"> :-- Describe that we are apply style sheet in whole xml page due to match attribute match="/"


<xsl:for-each select="catalog/cd"> :-- Its reach all the nodes under the catalog .

Hi.... an another example of Converting xml in to Html
My Student.xml page code
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="student.xsl"?>

<student>
          <Roll_number>
                        <Name>Deepak Sharma</Name>
                        <Class>5th</Class>
                        <Year>2010</Year>  
          </Roll_number>
          <Roll_number>
                        <Name>Arun Sharma</Name>
                        <Class>5th</Class>
                        <Year>2011</Year>  
          </Roll_number>
          <Roll_number>
                        <Name>Mohit Sharma</Name>
                        <Class>5th</Class>
                        <Year>2010</Year>  
          </Roll_number>

</student>
Just check it that i have already mention student.xsl in there head session.
The code of student.xsl is.....
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
          <table><tr>
                 <th>Name</th><th>Class</th></tr>
                  <xsl:for-each select="student/Roll_number">
                 <tr><td><xsl:value-of select="Name"/></td><td><xsl:value-of select="Year"/></td></tr>
                 </xsl:for-each>
          </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The xml style sheet flow chat like that....
1.<xsl:stylesheet version="" href="" ?></xsl:stylesheet>
2.<xsl:template></xsl:template>
3.<xsl:for-each></xsl:for-each>
4.<xsl:value-of select="">
Thanks




Tuesday, November 8, 2011

What is Xml NameSpace

Hi
I am start with some xml example let check this out......
<table>
  <tr>
    <td>Apples</td>
    <td>Bananas</td>
  </tr>
</table>
And another example of xml is
<table>
  <name>African Coffee Table</name>
  <width>80</width>
  <length>120</length>
</table>
As per the example both xml tag start with Table tag . so when we combined to gather there may be the chance of conflict.
An XML parser will not know how to handle these differences.

We can resolve the problem by Tar prefix like 
<h:table>
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>

<f:table>
  <f:name>African Coffee Table</f:name>
  <f:width>80</f:width>
  <f:length>120</f:length>
</f:table> 
The namespace is defined by the xmlns(xml namespace) attribute in the start tag of an element.
The namespace declaration has the following syntax. xmlns:prefix="URI".

<h:table xmlns:h="http://www.w3.org/TR/html4/">
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>

<f:table xmlns:f="http://www.w3schools.com/furniture">
  <f:name>African Coffee Table</f:name>
  <f:width>80</f:width>
  <f:length>120</f:length>
</f:table>
When a namespace is defined for an element, all child elements with the same prefix are associated with the same namespace.
Namespaces can be declared in the elements where they are used or in the XML root element:
<root
xmlns:h="http://www.w3.org/TR/html4/"
xmlns:f="http://www.w3schools.com/furniture"
>

<h:table>
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>

<f:table>
  <f:name>African Coffee Table</f:name>
  <f:width>80</f:width>
  <f:length>120</f:length>
</f:table>

</root> 

Namespaces in Real Use

XSLT is an XML language that can be used to transform XML documents into other formats, like HTML.
In the XSLT document below, you can see that most of the tags are HTML tags.
The tags that are not HTML tags have the prefix xsl, identified by the namespace xmlns:xsl="http://www.w3.org/1999/XSL/Transform":

Thanks It all about xml namespace . I will  post further in our next session.



Wednesday, October 12, 2011

How to integrate CSS in XML file.

Here i m showing some xml file test like...........

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="catalog.css"?>
<CATALOG>
  <CD>
    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>
    <COUNTRY>USA</COUNTRY>
  </CD>

</CATALOG>
In the above line i have mention there how to include css file reference with href tag
Now question is that how to declare the css property .
css file format here.

CATALOG
{
background-color: #ffffff;
width: 100%;
}
CD
{
display: block;
margin-bottom: 30pt;
margin-left: 0;
}
TITLE
{
color: #FF0000;
font-size: 20pt;
}
ARTIST
{
color: #0000FF;
font-size: 20pt;
}
COUNTRY
{
display: block;
color: #000000;
margin-left: 20pt;
}
Then its automatically worked with xml.
Thanks

Friday, September 23, 2011

TEXT BOX IN ASP.NET THROUGH CODING

Here is a form in which we want to display the test box on form loading.
<form id="form1" runat="server">
    <div>
       
    </div>
    </form>


In the page load method

protected void Page_Load(object sender, EventArgs e)
        {
            form1.Controls.Add(newTextBox());    //  
newTextBox() is the method who return the test box
        }

private TextBox newTextBox()
        {
            TextBox tx = new TextBox();

           
tx.ID = "TextBox1";
           
tx.Text = "some text";
           
tx.TextMode = TextBoxMode.MultiLine;
           
tx.Attributes.Add("runat", "server");
           
tx.Rows = 3;
           
tx.AutoPostBack = true;
                    
            tx.TextChanged += new EventHandler(tb_TextChanged);    // event handelar
           
            return tx;
        }


Try and enjoy

Wednesday, August 24, 2011

Asp.net Image validation.

In asp.net ,to validate the image extension you can use the regular expression like that.
<asp:RegularExpressionValidator ID="revImage" ControlToValidate="uplImage" ValidationExpression="^.*\.((j|J)(p|P)(e|E)?(g|G)|(g|G)(i|I)(f|F)|(p|P)(n|N)(g|G))$" Text=" ! Invalid image type" runat="server" /> 
Here the group of  image extension  array will check the extension and display the error message.