Saturday, June 30, 2012

What Is A Key? Describe Different Types Of Keys Used In Database?,define a relationship,



-A key is a single or combination of multiple fields.

-Its purpose is to access or retrieve data rows from table according to the requirement.

-The keys are defined in tables to access or sequence the stored data quickly and smoothly.

-They are also used to create links between different tables.

Primary Key


The attribute or combination of attributes that uniquely identifies a row or record in a relation is known as primary key.

Secondary key
-A field or combination of fields that is basis for retrieval is known as secondary key.

-Secondary key is a non-unique field. One secondary key value may refer to many records.

Candidate Key or Alternate key


-A relation can have only one primary key.

-It may contain many fields or combination of fields that can be used as primary key.

-One field or combination of fields is used as primary key.

-The fields or combination of fields that are not used as primary key are known as candidate key or alternate key.
-Composite key or concatenate key
A primary key that consists of two or more attributes is known as composite key.

Sort Or control key

-A field or combination of fields that is used to physically sequence the stored data called sort key. It is also known s control key.

Foreign Key


-A foreign key is an attribute or combination of attribute in a relation whose value match a primary key in another relation.

-The table in which foreign key is created is called as dependent table.

-The table to which foreign key is refers is known as parent table.

Comparison with 3tier architecture and MVC(model-view-controller) architecture



Both are smiler but topologically they are different.

-A Basic rule in a three tier architecture is the client tier never communicates directly with the data tier;
-in a three-tier model all communication must pass through the middle tier. Conceptually the three-tier architecture is linear

But


-MVC architecture is triangular

cycle in MVC(model-view-controller)

-view sends updates to the controller,

-the controller updates the model, and

-the view gets updated directly from the model.


3tier architecture and Multitier architecture



multi-tier architecture (often referred to as n-tier architecture) is a

client–server architecture in which

the presentation,
the application processing, and
the data management


are logically separate processes

The most widespread use of multi-tier architecture is the three-tier architecture.

There should be

a presentation tier,
a business or data access tier, and
a data tier.


Three-tier architecture


It was developed by John J. Donovan

The three-tier model is a software architecture and a software design pattern.

a change of operating system in the presentation tier would only affect the user interface code.





Presentation tier


-This is the topmost level of the application.

-The presentation tier displays information related to such services as browsing merchandise, purchasing, and shopping cart contents.

-It communicates with other tiers by outputting results to the browser/client tier and all other tiers in the network.

Application tier (business logic, logic tier, data access tier, or middle tier)

-The logic tier is pulled out from the presentation tier and, as its own layer, it controls an application’s functionality by performing detailed processing.

Data tier


-This tier consists of database servers.

-Here information is stored and retrieved.

-This tier keeps data neutral and independent from application servers or business logic. Giving data on its own tier also improves scalability and performance.


Data transfer between tiers is part of the architecture.

Protocols involved may include one or more of SNMP, CORBA, Java RMI, .NET Remoting, Windows Communication Foundation, sockets, UDP, web services or other standard or proprietary protocols.

Often middleware is used to connect the separate tiers.

Wednesday, June 27, 2012

Create PDF from DataTable in Asp.net,pdf generator without report viewer,

In this article ,i am explaining you how to create pdf file from datatable.i am passing a datatable in this function and code to convert this in pdf file. I am using iTextSharp you can download it from internet. it is free. you need to create a simple asp.net page and get data from database.Then pass it to ExportToPDF method. We can set PDF page margins, change page orientation (portrait, landscape), customize headers and footers add page numbers and more.Do some R & D with iTextSharp.
public void ExportToPdf(DataTable myDataTable)  
   {      
     Document pdfDoc = new Document(PageSize.A4, 10, 10, 10, 10);  
     try  
     {  
       PdfWriter.GetInstance(pdfDoc, System.Web.HttpContext.Current.Response.OutputStream);  
       pdfDoc.Open();  
       Chunk c = new Chunk("" + System.Web.HttpContext.Current.Session["CompanyName"] + "", FontFactory.GetFont("Verdana", 11));  
       Paragraph p = new Paragraph();  
       p.Alignment = Element.ALIGN_CENTER;  
       p.Add(c);  
       pdfDoc.Add(p);  
       string clientLogo = System.Web.HttpContext.Current.Session["CompanyName"].ToString();  
       clientLogo = clientLogo.Replace(" ", "");  
       string clogo = clientLogo + ".jpg";  
       string imageFilePath = System.Web.HttpContext.Current.Server.MapPath("../ClientLogo/" + clogo + "");  
       iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath);  
       //Resize image depend upon your need   
       jpg.ScaleToFit(80f, 60f);  
       //Give space before image   
       jpg.SpacingBefore = 0f;  
       //Give some space after the image   
       jpg.SpacingAfter = 1f;  
       jpg.Alignment = Element.HEADER;  
       pdfDoc.Add(jpg);  
       Font font8 = FontFactory.GetFont("ARIAL", 7);  
       DataTable dt = myDataTable;  
       if (dt != null)  
       {  
         //Craete instance of the pdf table and set the number of column in that table  
         PdfPTable PdfTable = new PdfPTable(dt.Columns.Count);  
         PdfPCell PdfPCell = null;  
         for (int rows = 0; rows < dt.Rows.Count; rows++)  
         {  
           for (int column = 0; column < dt.Columns.Count; column++)  
           {  
             PdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows][column].ToString(), font8)));  
             PdfTable.AddCell(PdfPCell);  
           }  
         }  
         //PdfTable.SpacingBefore = 15f; // Give some space after the text or it may overlap the table            
         pdfDoc.Add(PdfTable); // add pdf table to the document   
       }  
       pdfDoc.Close();  
       Response.ContentType = "application/pdf";  
       Response.AddHeader("content-disposition", "attachment; filename= SampleExport.pdf");  
       System.Web.HttpContext.Current.Response.Write(pdfDoc);  
       Response.Flush();  
       Response.End();  
       //HttpContext.Current.ApplicationInstance.CompleteRequest();  
     }  
     catch (DocumentException de)  
     {  
       System.Web.HttpContext.Current.Response.Write(de.Message);  
     }  
     catch (IOException ioEx)  
     {  
       System.Web.HttpContext.Current.Response.Write(ioEx.Message);  
     }  
     catch (Exception ex)  
     {  
       System.Web.HttpContext.Current.Response.Write(ex.Message);  
     }  
   }  

Tuesday, June 26, 2012

SiteMapPath using asp.net,example of SiteMapPath,with screenshot,why we use



ButtonExample.aspx

  1. <%@ Page Language="C#" %>  
  2. <%@ Import Namespace="System.Drawing" %>  
  3.   
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  5.   
  6. <script runat="server">  
  7.     protected void Button1_Click(object sender, System.EventArgs e)  
  8.     {  
  9.         SiteMapPath1.BackColor = Color.Cornsilk;  
  10.         SiteMapPath1.ForeColor = Color.Crimson;  
  11.         SiteMapPath1.Font.Size = FontUnit.Large;  
  12.         SiteMapPath1.Font.Italic = true;  
  13.         SiteMapPath1.PathSeparator = " / ";  
  14.         SiteMapPath1.NodeStyle.ForeColor = Color.PaleVioletRed;  
  15.         SiteMapPath1.Font.Bold = true;  
  16.         SiteMapPath1.RootNodeStyle.Font.Size = FontUnit.XLarge;  
  17.     }  
  18. </script>  
  19.   
  20. <html xmlns="http://www.w3.org/1999/xhtml">  
  21. <head id="Head1" runat="server">  
  22.     <title>How to set, change SiteMapPath style programmatically</title>  
  23. </head>  
  24. <body>  
  25.     <form id="form1" runat="server">  
  26.     <div>  
  27.         <h2 style="color:Navy">SiteMapPath Example: Style</h2>  
  28.         <asp:SiteMapPath   
  29.              ID="SiteMapPath1"   
  30.              runat="server"  
  31.              >  
  32.         </asp:SiteMapPath>  
  33.         <br /><br /><br /><br />  
  34.         <asp:Button   
  35.              ID="Button1"   
  36.              runat="server"  
  37.              ForeColor="SteelBlue"  
  38.              Text="Change SiteMapPath Style"  
  39.              Height="45"  
  40.              OnClick="Button1_Click"  
  41.              Font-Bold="true"  
  42.              />  
  43.     </div>  
  44.     </form>  
  45. </body>  
  46. </html>  

Web.sitemap

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="Default.aspx" title="Home"  description="Home Page">
    <siteMapNode url="StandardToolBox.aspx" title="StandardToolBox" description="StandardToolBox Controls">
      <siteMapNode url="AdRotatorExample.aspx" title="AdRotator"  description="AdRotator Example" />
      <siteMapNode url="BulletedListExample.aspx" title="BulletedList"  description="BuulletedList Example" />
      <siteMapNode url="ButtonExample.aspx" title="Button"  description="Button Example" />
      <siteMapNode url="CalendarExample.aspx" title="Calendar"  description="Calendar Example" />
    </siteMapNode>
    <siteMapNode url="DataToolBox.aspx" title="DataToolBox" description="DataToolBox controls">
      <siteMapNode url="ListViewExample.aspx" title="ListView"  description="ListView Example" />
      <siteMapNode url="GridViewExample.aspx" title="GridView"  description="GridView Example" />
    </siteMapNode>
    <siteMapNode url="NavigationToolbox.aspx" title="Navigation Toolbox" description="NavigationToolbox controls">
      <siteMapNode url="MenuExample.aspx" title="Menu"  description="Menu Example" />
      <siteMapNode url="SiteMapPathExample.aspx" title="SiteMapPath"  description="SiteMapPath Example" />
      <siteMapNode url="TreeViewExample.aspx" title="TreeView"  description="TreeView Example" />
    </siteMapNode>
  </siteMapNode>
</siteMap>






Sunday, June 24, 2012

Introduction to XPath for ASP.NET Developers




Tree like representation of an XML Document
In XPath, an XML document is represented as a tree of nodes. There is a parent node with one or more child nodes.

While a node in XPath can be of 7 types; for practical purposes, a node in XPath corresponds to an element or attribute within an XML document.

For example, have a look at following XML document:

<?xml version="1.0" encoding="utf-8" ?>
<userinfo>
 <username admin="true">someUserName1</username>
 <email>xyz@whatever.com</email>
</userinfo>

Following is XPath's tree representation of the above document:
  • userinfo
    • username
      • admin
    • email

Each node is related to the nodes above and below it. In our XML document above, userinfo is root node.

userinfo is the parent of username and email nodes. username and email nodes are siblings.

username and email are children of userinfo node. Similarly, admin is the child of username node.

Selecting Nodes within an XML Document

Now that we understand how elements and attributes are represented as nodes in XPath, we will focus on how to use XPath expressions to select one or more nodes within an XML document.

XPath Expressions
Following are some of the expressions that you can use to select one or more nodes from the XML document above:

/userinfo - Selects the root element.
/userinfo/username - Selects the username node which is the child of userinfo root node.
//email - Selects all the nodes in the document which match the name (email) irrespective of where they lie in the document.
//username[@admin] - Selects all nodes with the name of "username" which have an attribute; "admin".
/userinfo/username[1] - Selects the first username node that is the child of userinfo node.
/userinfo/username[last()] - Assuming userinfo had more than one username child nodes, it will return the last username node that is the child of userinfo node.

Practical Demonstration of XPath Expressions

We will now create a sample XML document and then use XPath expressions to select and display only few nodes from it.

Sample XML Document
Copy and paste following text in a new text file and save it as "sample.xml" in the /App_Data folder of your ASP.NET web application:

<?xml version="1.0" encoding="utf-8" ?>
<article>
 <author isadmin="true">Faisal Khan</author>
 <title>Sample XML Document</title>
 <body>
  <page>This is page #1.</page>
  <page>This is page #2.</page>
  <page>This is page #3.</page>
 </body>
</article>


XPath.aspx ASP.NET Page
Now, we will create the ASP.NET page which will read the above sample.xml file and selectively display its contents using XPath.

Copy and paste the following text into a new text file and save it as "XPath.aspx"
in your ASP.NET web application:


<%@ Page Language="C#" AutoEventWireup="true" %>

<%@ Import Namespace="System.Xml" %>

<script runat="server">
 protected void Page_Load(object source, EventArgs e)
 {
  XmlDocument doc = new XmlDocument();
  doc.Load(Server.MapPath("~/App_Data/sample.xml"));

  XmlNodeList nodes = doc.SelectNodes("/article/body/page");

  foreach (XmlNode node in nodes)
  {
   TableRow row = new TableRow();
   TableCell cell = new TableCell();
   cell.Text = node.FirstChild.InnerText;

   row.Cells.Add(cell);
   PagesTable.Rows.Add(row);
  }
 }
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Using XPath Expressions</title>
    <style type="text/css">
  body { font-family: Verdana; font-size: 9pt; }
  .name { background-color: #F7F7F7; }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
  <asp:Table id="PagesTable" runat="server" />
    </div>
    </form>
</body>
</html>

We will look into its code a little later, for now when this ASP.NET page was run on my computer, it produced following result (displaying only page elements from the XML file):

Looking into the Code

We learned how to read an XML file and display its contents using XmlDocument class from System.Xml namespace in an ASP.NET page, in previous tutorial. We will focus in this tutorial on how to use XPath expressions to only selectively return the list of nodes we want to display to the user.

protected void Page_Load(object source, EventArgs e)
{
 XmlDocument doc = new XmlDocument();
 doc.Load(Server.MapPath("~/App_Data/sample.xml"));

 XmlNodeList nodes = doc.SelectNodes("/article/body/page");

 foreach (XmlNode node in nodes)
 {
  TableRow row = new TableRow();
  TableCell cell = new TableCell();
  cell.Text = node.FirstChild.InnerText;

  row.Cells.Add(cell);
  PagesTable.Rows.Add(row);
 }
}

We create a new instance of XmlDocument class and make it load our "sample.xml" file. Next, we want to only display the page elements so we use a simple XPath expression; "/article/body/page" to select only the page nodes.

XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("~/App_Data/sample.xml"));

XmlNodeList nodes = doc.SelectNodes("/article/body/page");

Next, we iterate through the returned list of XmlNodes and insert its contents in our ASP.NET table. To get the text from the page element in XML file, we use XmlNode.FirstChild.InnerText property.

foreach (XmlNode node in nodes)
{
 TableRow row = new TableRow();
 TableCell cell = new TableCell();
 cell.Text = node.FirstChild.InnerText;

 row.Cells.Add(cell);
 PagesTable.Rows.Add(row);
}

Some More XPath Expressions
Had we only wanted to fetch the first page element from the XML document, what is the XPath expression we should have used? And what if we wanted to return only the last page element?

What is Debug? how to debug the program?



Computer programmers, like everybody else, are not perfect. This means the programs they write sometimes have small errors, called "bugs," in them. These bugs can be minor, such as not recognizing user input, or more serious, such as a memory leak that crashes the program.

Before releasing their software to the public, programmers "debug" their programs, eliminating as many errors as possible.

This debugging process often takes a long time, as fixing some errors may introduce others.

Debugging your windshield at a gas station is much easier than debugging a computer program.