Showing posts with label Database. Show all posts
Showing posts with label Database. Show all posts

12 rules of CODD for RDBMS (relational database management system).

  1. Foundation Rule
    A relational database management system must manage its stored data using only its relational capabilities.
  2. Information Rule
    All information in the database should be represented in one and only one way - as values in a table.
  3. Guaranteed Access Rule
    Each and every datum (atomic value) is guaranteed to be logically accessible by resorting to a combination of table name, primary key value and column name.
  4. Systematic Treatment of Null Values
    Null values (distinct from empty character string or a string of blank characters and distinct from zero or any other number) are supported in the fully relational DBMS for representing missing information in a systematic way, independent of data type.
  5. Dynamic On-line Catalog Based on the Relational Model
    The database description is represented at the logical level in the same way as ordinary data, so authorized users can apply the same relational language to its interrogation as they apply to regular data.
  6. Comprehensive Data Sublanguage Rule
    A relational system may support several languages and various modes of terminal use. However, there must be at least one language whose statements are expressible, per some well-defined syntax, as character strings and whose ability to support all of the following is comprehensible:
    1. data definition
    2. view definition
    3. data manipulation (interactive and by program)
    4. integrity constraints
    5. authorization
    6. transaction boundaries (begin, commit, and rollback).
  7. View Updating Rule
    All views that are theoretically updateable are also updateable by the system.
  8. High-level Insert, Update, and Delete
    The capability of handling a base relation or a derived relation as a single operand applies nor only to the retrieval of data but also to the insertion, update, and deletion of data.
  9. Physical Data Independence
    Application programs and terminal activities remain logically unimpaired whenever any changes are made in either storage representation or access methods.
  10. Logical Data Independence
    Application programs and terminal activities remain logically unimpaired when information preserving changes of any kind that theoretically permit unimpairment are made to the base tables.
  11. Integrity Independence
    Integrity constraints specific to a particular relational database must be definable in the relational data sublanguage and storable in the catalog, not in the application programs.
  12. Distribution Independence
    The data manipulation sublanguage of a relational DBMS must enable application programs and terminal activities to remain logically unimpaired whether and whenever data are physically centralized or distributed.
  13. Nonsubversion Rule
    If a relational system has or supports a low-level (single-record-at-a-time) language, that low-level language cannot be used to subvert or bypass the integrity rules or constraints expressed in the higher-level (multiple-records-at-a-time) relational language. 
Referances:
http://www.cse.ohio-state.edu/~sgomori/570/coddsrules.html

How to show multiple columns in the single dropdown list using sqlreader?

Here i will show you how can u bind the multiple columns ti the single dropdown list..

Steps:
Add dropdown list from toolbox.
Now bind the data at the page load event of the page.

protected void Page_Load(object sender, EventArgs e)
    {
       string connectionString = 
"Data Source=VRAKSH-VAIBHAVS;Initial Catalog=AdventureWorks;Persist Security Info=True;User ID=sa;Password=data#123";
       SqlConnection con = new SqlConnection(connectionString);
       SqlCommand cmd = new SqlCommand 
("select City + ' ' + PostalCode as PCity from Person.Address", con);
       con.Open();
       SqlDataReader rd;
       rd = cmd.ExecuteReader();
        DataSet ds = new DataSet();
        DropDownList1.DataSource = rd;
        DropDownList1.DataValueField = "PCity";
       DropDownList1.DataBind();
        con.Close();
    }
 
 
 Remember to bind the data source to the dropdown list .....
& also bind the column to the drop down list like i did i.e.
DropDownList1.DataValueField = "PCity"
 
Like this you can bind multiple columns to the dropdown list .... 
 

How to import data from excel file to grid view ?

Here i will show that how can we import data from the excel file to gridview....
we will be using OLEDB instead of SQL because we will be using excel file as database & not sqlserver.
In HTML code just take the gridview & on button named Import.
I will look something like this....

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile
="WebImportExport.aspx.cs"
Inherits
="Forms_WebImportExport" %>
<
html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<
title>Untitled Page</title>
<
/head>
<
body>
<
form id="form1" runat="server">
<div>
<
asp:Button ID="Import" runat="server"
OnClick="Import_Click" Text="Import" />
<br />
<
asp:GridView ID="GridView1" runat="server">
<
/asp:GridView>
<
br />
<
/div>
<
/form>
<
/body>
<
/html>



In Code behind...

using System.Data.OleDb;
using
System.IO;

public
partial class Import_ExcelToGrid : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void Import_Click(object sender, EventArgs e)
{
OleDbconnection con = new OleDbconnection
(@"Provider=Microsoft.Jet.OLEDB.4.0;
Data
Source=C:\\path\\vaibhav.xls;

Extended Properties=\"Excel 8.0;\
");
OleDbDataAdapter oleDA = new OleDbDataAdapter
("SELECT name , dept, salary from [sheet1$]", con);
DataSet ds = new DataSet();
oleDA.Fill(ds);
GridView
1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
Here i will pass my excel file in string which have to be imported to the gridview.

This will import he data from exel file to the gridview.

Exporting data from GridView to pdf file in asp.net or how to export data from gridview to pdf in c#?

<!--[if gte mso 9]> Normal 0 false false false EN-IN X-NONE X-NONE MicrosoftInternetExplorer4

In this demo tutorial I will show you how to export data from gridview to pdf file.

Steps are as follows:

1. Create new web page.

2. Drag & drop gridview from toolbox & bind your database (don’t use enable sorting).

<asp:GridView ID="GridView2" runat="server">
        asp:GridView>

3. Drag & drop button.

  <asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />

4. You need to download one dll file named iTextSharp.dll.

5. Now add reference of this downloaded dll.

6. Now go to code behind & some of the following codes.

using iTextSharp.text;

using iTextSharp.text.pdf;

using iTextSharp.text.html.simpleparser;


7. Now add following code in code behind.

public override void VerifyRenderingInServerForm(Control control)

{

/* Verifies that the control is rendered */

}

protected void Button1_Click(object sender, EventArgs e)

{

Response.ContentType = "application/pdf";

Response.AddHeader("content0disposition",

"attachment;filename=UserDetails.pdf");

Response.Cache.SetCacheability(HttpCacheability.NoCache);

StringWriter sw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(sw);

GridView1.AllowPaging = false;

GridView1.DataBind();

GridView1.RenderControl(hw);

GridView1.HeaderRow.Style.Add("width", "15%");

GridView1.HeaderRow.Style.Add("font-size", "10px");

GridView1.Style.Add("text-decoration", "none");

GridView1.Style.Add("font-family", "Arial, Helvetica, sans-serif");

GridView1.Style.Add("font-size", "8px");

StringReader sr = new StringReader(sw.ToString());

StreamReader reader = new StreamReader(new MemoryStream(Encoding.ASCII.Ge tBytes(sw.ToString())));

Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);

HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

pdfDoc.Open();

htmlparser.Parse(reader);

pdfDoc.Close();

Response.Write(pdfDoc);

Response.End();

}

Now on button click , whole data from your gridview will be transferred in pdf file .




How to get data from database into xml ?

It is very easy code....
You just have to use WriteXml() function

here is sample code.........

public DataSet GetLocationByMandate()

{

new SqlConnection("Data Source=.;Initial Catalog=login;Integrated Security=True");

DataSet Ds = new DataSet();

SqlDataAdapter Da = new SqlDataAdapter("your quary",connection);

Da.Fill(Ds);

Ds.WriteXml("locations1.xml");

}