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