Friday, October 25, 2013

primary key


max no of primary keys in single table is 16

create table my_table1 (
     column_a1 integer not null,
     column_a2 integer not null,
     column_a3 integer not null,
     column_a4 integer not null,
     column_a5 integer not null,
     column_a6 integer not null,
     column_a7 integer not null,
     column_a8 integer not null,
     column_a9 integer not null,
     column_a10 integer not null,
     column_a11 integer not null,
     column_a12 integer not null,
     column_a13 integer not null,
     column_a14 integer not null,
     column_a15 integer not null,
     column_a16 integer not null,
     column_a17 integer not null,
    primary key (column_a1, column_a2, column_a3, column_a4,
 column_a5, column_a6, column_a7, column_a8, column_a9,
column_a10, column_a11, column_a12, column_a13, column_a14,
column_a15, column_a16)
);

Magic Tables In SqlServer

MAGIC TABLES...
------------------------------------------------------------------------------------
SQL Server allows you to define a Magic Table. Magic Tables are invisible tables
 or virtual tables. You can see them only with the help Triggers in SQL Server.
Magic Tables are those tables which allow you to hold inserted, deleted and
updated values during insert, delete and update DML operations on a table in
SQL Server. So let's have a look at a practical example of how to use Magic Tables
 in SQL Server. The example is developed in SQL Server 2012 using the SQL Server
 Management Studio.

 --> These are the two Magic Tables:

     1) Inserted
     2) Deleted

Generally Magic Tables are invisible tables, we can only see them with the help
of Trigger's in SQL Server.

    CREATE TABLE TEST (SNO INT,SNAME VARCHAR(50),SLOC VARCHAR(50))

Insert Below Data First
-----------------------
1) insert into TEST values(1, 'KISH','KURNOOL');
2) insert into TEST values(2, 'SAI','KURNOOL');
3) insert into TEST values(3, 'HARI','KURNOOL');
4) insert into TEST values(4, 'RAVI','WARANAGL');
5) insert into TEST values(5, 'YES','WGL');
6) insert into TEST values(6, 'NO','WG');

select * from test order by sno;

1) Inserted :
-------------
       ALTER TRIGGER  Trigger_ForInsertmagic ON TEST
       FOR INSERT AS
       begin
         SELECT * FROM INSERTED
       end

7) insert into TEST values(7, 'SRINU','PRAKASHAM');
running the above query it will fire the trigger  Trigger_ForInsertmagic and shows below result automatically
7 SRINU PRAKASHAM

--> upon inserting the record in table (TEST) it shows the inserted data automatically ,when we write the above trigger by using magic tables

select * from test order by sno;
--------------------------------
1 KISH KURNOOL
2 SAI KURNOOL
3 HARI KURNOOL
4 RAVI WARANAGL
5 YES WGL
6 NO WG
7 SRINU PRAKASHAM


2) Updated:
-------------
       ALTER TRIGGER  Trigger_ForUpdatemagic ON TEST
       FOR UPDATE AS
       begin
         SELECT * FROM INSERTED
       end

UPDATE TEST SET SNAME='raju' WHERE SNO=3;
running the above query it will fire the trigger  Trigger_ForUpdatemagic and shows below result
3 raju KURNOOL
--> upon Updating the record in table (TEST) it shows the Updated data automatically ,when we write the above trigger by using magic tables

select * from test order by sno;
1 KISH KURNOOL
2 SAI KURNOOL
3 raju KURNOOL
4 RAVI WARANAGL
5 YES WGL
6 NO WG
7 SRINU PRAKASHAM


2) Deleted :
------------
       ALTER TRIGGER  Trigger_ForDeleteMagic ON TEST
       FOR DELETE AS
       begin
         SELECT * FROM DELETED
       end

DELETE FROM TEST WHERE SNO=7;
running the above query it will fire the trigger  Trigger_ForDeleteMagic and shows below result
7 SRINU PRAKASHAM

--> upon Deleting the record in table (TEST) it shows the Deleted data automatically ,when we write the above trigger by using magic tables
     SELECT * FROM TEST;
1 KISH KURNOOL
2 SAI KURNOOL
3 raju KURNOOL
4 RAVI WARANAGL
5 YES WGL
6 NO WG

if we delete not available value , it will show empty result

Wednesday, October 23, 2013

Boxing And UnBoxing

Boxing And UnBoxing

Boxing:
          if a value type is stored in a reference type variable we call it boxing.
                 int x=100;
                 object obj=x;
           if a reference type which contains value type in it if converted back into a value type we call it as unboxing.
              int y=convert.toint32(obj);



Data Types

Data Types


                 data types are divided in to two categories
                                 1.value types
                                 2.reference types
Value Types:
                  value types stored the data on stack ,which is a place.where  the data is stored fixed length.such as
  • bool
  • byte
  • char
  • decimal
  • double
  • enum
  • float
  • int
  • long
  • sbyte
  • short
  • struct
  • uint
  • ulong
  • ushort

Reference Types:
                        these are stored in heap memory which is other place where data an be stored C# supports two preferred reference types
  • class
  • interface
  • delegate
  • object
  • string
    in .net the heap is now more managed and called managed heap. which will be under control of garbage collector providing automatic memory management
                       

Encapsulation Example

Encapsulation:

Encapsulation is a process of binding the data members and member functions into a single unit.
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    public class Aperture
  {
   public Aperture ()
    {
    }
   protected double height=10;
   protected double width=20;
   protected double thickness=30;
  public double  volume()
  {
   
  Double volume=height * width * thickness;
  if (volume<0)
  return 0;
  return volume;
 }
  static void Main(string[] args)
  {
      Aperture obj = new Aperture();
      Console.WriteLine( obj.volume());
      Console.Read();
  }
 }
 }

Jquery Grid View

Hi My Dear Friends, here i am going to explain how to use JQuery GridView in WebForm.

By Default this Jquery Grid supports Sorting, Pagging and Searching the data within the Grid with good look and feel.

To Start this...

File -> New -> Website -> Name it as "YourWebSiteName" (Here I used as Jgrid).

In the Default.aspx page add the following Script files in the <head> tag.

<link href="css/jquery-ui.css" rel="stylesheet" type="text/css" />
<link href="css/jquery.dataTables_themeroller.css" rel="stylesheet" type="text/css" />

<script src="css/jquery.js" type="text/javascript"></script>

<script src="css/jquery.dataTables.min.js" type="text/javascript"></script>

<script src="css/jquery-ui-1.9.2.custom.min.js" type="text/javascript"></script>


In the following project add the following script files in the css folder.

Jquery-ui.css
jquery.dataTables_themeroller.css
jquery.js
jquery.dataTables.min.js
jquery-ui-1.9.2.custom.min.js


Add the Following JavaScript code which applies the Jquery Grid Styles to our Normal GridView.

<script type="text/javascript">
var oTable;
$(document).ready(function() {
$('#GridView1').dataTable({
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"iDisplayLength": 10,
"aaSorting": [[0, "asc"]],
"bJQueryUI": true,
"bAutoWidth": false,
"bProcessing": true,
"sDom": '<"top"i><"title">lt<"bottom"pf>',
"sPaginationType": "full_numbers",
"bRetrieve": true,

//----Scrolling----
"sScrollY": "275px",
"sScrollX": "100%",
"sScrollXInner": "100%",
"bScrollCollapse": true,

// ---- Print_Export_Copy ----
"sDom": 'T<"clear"><"H"lfr>t<"F"ip>',
"oLanguage": {
"sZeroRecords": "There are no Records that match your search critera",
"sLengthMenu": "Display _MENU_ records per page&nbsp;&nbsp;",
"sInfo": "Displaying _START_ to _END_ of _TOTAL_ records",
"sInfoEmpty": "Showing 0 to 0 of 0 records",
"sInfoFiltered": "(filtered from _MAX_ total records)",
"sEmptyTable": 'No Rows to Display.....!',
"sSearch": "Search all columns:"
},

"oSearch": {
"sSearch": "",
"bRegex": false,
"bSmart": true
},
});

$('#GridView1 tbody td').click(function() {
var aPos = oTable.fnGetPosition(this);
var aData = oTable.fnGetData(aPos[0]);
});

/* Init the table */
oTable = $('#GridView1').dataTable();
});

</script>



In Code Behind.....

In Page_load bind the data to the gridview1.

string strConnect = "server=xxxxxxxxx; user id=xxxx; pwd=xxxxxxx; database=xxxxxxxxxxxxx;";

DataSet dataset = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select DEPARTMENTID,DEPARTMENTNAME,DEPARTMENTHEAD,VCHSTATUS,VCHCREATEDBY from TABDEPARTMENT", strConnect);
da.Fill(dataset, "polls");

GridView1.DataSource = dataset;
GridView1.DataBind();


Add the following events to the GridView Control...

OnPreRender="GridView1_PreRender"
OnRowDataBound="GridView1_RowDataBound"


protected void GridView1_PreRender(object sender, EventArgs e)
{
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
GridView1.FooterRow.TableSection = TableRowSection.TableFooter;
GridView1.FooterRow.Cells.Clear();
}



protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes.Add("onmouseover", "this.style.cursor='pointer'; tempColour = this.style.backgroundColor; this.style.backgroundColor='#2187AF';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=tempColour;");
}



For Further Details