Friday, July 1, 2011

How to access the Asp.Net data using JQuery

How to access the Asp.Net data using JQuery:

The below article simple example how to access the web method returns values using JQuery.

JQuery:


  • JQuery is library of java script functions.
  • JQuery is light-weight component.
  • Write less Do More.
  • Cross – browser independent.


JQuery with Asp.Net:

JQuery is on JavaScript file. We need to include this file on our web applications. I don’t have idea if this able to use on dot net 1.1 Version. We can able to use on 2.0 and above dot net versions.

In dot net 2.0 versions JQuery is not Intellisense. It’s an Intellisense above dot net 2.0 versions.

Steps for JQuery installation on Asp.Net:

1.Download JQuery application from http://jquery.com [Latest Release].
2.Add the .js file web application.
3.Include the .js file in your web page.

Access the web service using JQuery:

The below elements to known before create access method.


  1. $.ajax() is a JQuery Method to make AJAX calls.
  2. Type=”Post”
  3. Data – Used to pass the parameter to web method.
  4. contentType – “applicaton/json; charset=utf-8” for JSon Web service.
  5. Datatype : JSON
  6. Success : This function is called after success processing happened.


Coding:

function ajaxJson() {
$.ajax({
type: "POST",
url: "JSON.asmx/AjaxJSON",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
var data = eval("(" + msg + ")");
var t = "" + " "; jQuery.each(data, function(rec) { workflow = workflow + " "; }); t = t + "
Journal " +
"Volume
" +
"Issue
" +
"Article
" + this.journal + " " + this.volume + " " + this.issue + " " + this.article + "
";

$("#jsonDiv").html(workflow);
},
error: function(msg) {

}
});
};










.

Monday, June 20, 2011

JSON with Asp.Net Application

JSON with Asp.Net Applications:

JSON:

JSON - Java Script Object Notation. JSON is light weight data-interchange component.

JSON with Asp.Net Web Services:

.Net Web services returns data on format of SOAP - Xml. JSON is better than compare with Xml. JSON easily parsed by java script. This article provides the solution, how to .net web service returns the format of JSON.

Requirements:

1. Dot Net 2005
2. C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025

References:

1. Add reference System.Web.Services.

Service.cs:

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using System.Collections.Generic;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]

public class Service : System.Web.Services.WebService
{

public Service ()
{

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}


[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string TestJson()
{
Database dc=new Database ();
List lstjrnlobj = new List();
lstjrnlobj = dc.GetJournalData();
return new JavaScriptSerializer().Serialize(lstjrnlobj);
}

}


Database.cs:


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Collections;
using System.Collections.Generic;

///
/// Summary description for Database
///

public class Database
{
MySqlConnection conn;
MySqlCommand cmd;
MySqlDataReader dr;
string qry = string.Empty;
public Database()
{
conn = new MySqlConnection(ConfigurationSettings.AppSettings["conn"].ToString());
}
public List GetJournalData()
{
List lstjrnlobj = new List();
try
{
conn.Open();
qry="select journal,volume,issue,article from workflow where journal='ji' and volume='186' and issue='1'";
cmd = new MySqlCommand(qry, conn);
dr = cmd.ExecuteReader();
while (dr.Read ())
{
JournalObj jobj=new JournalObj ();
jobj.Journal =dr["journal"].ToString ();
jobj.Volume = dr["volume"].ToString();
jobj.Issue = dr["issue"].ToString();
jobj.Articleid = dr["article"].ToString();
lstjrnlobj.Add(jobj);
}
return lstjrnlobj;
}
catch
{
return null;
}
finally
{
conn.Close();
}

}
}


Journalobj.cs:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

///
/// Summary description for JournalObj
///

public class JournalObj
{
public JournalObj()
{

}

private string _journla;

public string Journal
{
get { return _journla; }
set { _journla = value; }
}

private string _volume;

public string Volume
{
get { return _volume; }
set { _volume = value; }
}

private string _issue;

public string Issue
{
get { return _issue; }
set { _issue = value; }
}

private string _articleid;

public string Articleid
{
get { return _articleid; }
set { _articleid = value; }
}


}

JSON Output:




[{"Journal":"JI","Volume":"186","Issue":"1","Articleid":"1001807"},{"Journal":"JI","Volume":"186","Issue":"1","Articleid":"0903227"},{"Journal":"JI","Volume":"186","Issue":"1","Articleid":"0903314"},{"Journal":"JI","Volume":"186","Issue":"1","Articleid":"1000290"},{"Journal":"JI","Volume":"186","Issue":"1","Articleid":"1000800"},{"Journal":"JI","Volume":"186","Issue":"1","Articleid":"1002873"},{"Journal":"JI","Volume":"186","Issue":"1","Articleid":"1002230"},{"Journal":"JI","Volume":"186","Issue":"1","Articleid":"1090121"},{"Journal":"JI","Volume":"186","Issue":"1","Articleid":"186_1"},{"Journal":"JI","Volume":"186","Issue":"1","Articleid":"1001963"},{"Journal":"JI","Volume":"186","Issue":"1","Articleid":"186_1"}]

Thursday, June 2, 2011

How Index's are Working

How Index’s are working?

Before Creating how  index is working:

Journal
Volume
Issue
Article
JOP
101
2
2436
HPJ
153
0
7841
ASEM
0
0
3251
JOP
101
2
5621
             
  

Now we search the Journal “JOP” and article “5621”. It’s Read entire table and provide data.

After Creating Index for Table Structure:

Index Created for Journal Column:


Journal
JOP
HPJ
ASEM


The above index refer the relevant journal in the below table.

Journal
Volume
Issue
Article
JOP
101
2
2436
HPJ
153
0
7841
ASEM
0
0
3251
JOP
101
2
5621









After creating index for the “journal” column now it’s not read entire data, based on the index column its retrieve data more quickly. We can able to identify the difference at the time large table only.

Wednesday, June 1, 2011

Indexing in SQL Server 2000


Indexing in SQL Server 2000:

                What is an index?

                                The simplest example for the index is book.  In book have the chapters, it have front page of the index. Using index we can easily get the information (go through that chapter).

                In SQL Server indexing is used to fetch the information in fastest way.

                There are two different types of index’s are available,
i.                     Cluster Index
ii.                   Non Cluster Index

Important points of index:

a.       Retrieve the records from the database with large number of records. If we have minimum level of records could not find any difference.

b.      When we use index we do index DML (Insert, Delete, Update) operation in query, in this case it takes some time. If any DML Operation performed in database that time index has been re arranged (changed from in existing location).

c.       We set index for frequently accessible columns.

d.      Creating index using the below commands,

CREATE INDEX index_name 
ON table_name (column_name1, column_name2...); 
CREATE UNIQUE INDEX index_name 
ON table_name (column_name1, column_name2...); 

e.      Index values are stored in disk. This space occupied based on the table. We can able to view using the below command,

EXEC sp_spaceused 

               

Monday, May 30, 2011

Check / Uncheck All Option in Grid view Using JavaScript



Grid View Coding:

<asp:GridView ID="grid_msprep" runat="server" AutoGenerateColumns="false" SkinID="gridviewSkin">
<Columns>
<asp:TemplateField HeaderText="S.No">
<ItemTemplate>
<%#Container.DataItemIndex +1 %>
ItemTemplate>
asp:TemplateField>
<asp:BoundField HeaderText="Journal" DataField="journal" />
<asp:BoundField DataField="article" HeaderText="Article" />
<asp:BoundField DataField ="volume" HeaderText="Volume" />
<asp:BoundField DataField ="issue" HeaderText="Issue" />                           
<asp:BoundField DataField ="category" HeaderText="Category" />
<asp:TemplateField HeaderText="Select">
<HeaderTemplate>
<asp:CheckBox ID="chkall" runat="server" onclick="checkAll(this,'grid_msprep','6')" Text="Check / UnCheck All" />
HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkselect" runat="server" />
ItemTemplate>
asp:TemplateField>
Columns>
asp:GridView>

Java Script:

function checkAll(chkValue,gridId,chkBoxColumn)
{  
        var gridview = document.getElementById(gridId);       
        for(var i = 1;i < gridview.rows.length; i++)
        {
                gridview.rows[i].cells[chkBoxColumn].firstChild.checked = chkValue.checked ;           
        }
}

Friday, May 27, 2011

Difference between unique and primary key

Unique and primary key enforces the uniqueness of the column.
Primary key creates with index column and unique key as non-cluster index another main difference is primary key not allowed "Null" Values as well as unique key allows one "Null" only.

Code Review Tools For Dot Net


Code Review Tools:

                As I have found the below two code review tools for .dot net
·         StyleCop
·         FoxCop
Both these tools are freeware edition and this need to be integrated with Dot Net IDE.

How StyleCop Tool Review the Code:

                In default the tool has some validation points for code review. This is would be checked for every code review process.
                We can able to add / delete the code review check list points.

Version Details: Microsoft StyleCop 4.3.3.0 (Dot Net 2005)

C# Rule Settings:

1.       Documentation Rules
2.       Layout Rules
3.       Maintainability Rules
4.       Naming Rules
5.       Ordering Rules
6.       Readability Rules
7.       Spacing Rules

The above rules have the validation points.  Please find the below important validation points

1.       Access Modifier Must Be Declared
2.       Interface Names Must Begin With (I)
3.       Use String Empty For Empty Strings