ASPX
CodeBehind
Thursday, October 11, 2007
Monday, October 8, 2007
How the word 'Interface' came into OOP terminology
I thought of framing the question as (why the name for Interface is interface in Object Oriented Programming) :-). What ever, Just keep OOP aside and think what is an 'interface'?. What is the interface to your home/room/office?.
Interface is nothing but the way an object get exposed to the external world. That means you can play around with any object by its interface only. Now come to OOPs. U can play around with an object/class using its variables and its methods only(Is it Not?). Therefore interface to(of) a class is nothing but a its(class's) variables and method signatures.
Now come to Interface in OOPs..Afterall interface is also a class but it just consist only the variables and method signatures. Hence A class which just contains the details of its interface is called Interface.
Interface is nothing but the way an object get exposed to the external world. That means you can play around with any object by its interface only. Now come to OOPs. U can play around with an object/class using its variables and its methods only(Is it Not?). Therefore interface to(of) a class is nothing but a its(class's) variables and method signatures.
Now come to Interface in OOPs..Afterall interface is also a class but it just consist only the variables and method signatures. Hence A class which just contains the details of its interface is called Interface.
JavaScript Email Validation
function validate_Email()
{
// Author: Surendra Sambana
//Purpose: Email validation using java script
// One can improve this using regular expressions.
var strEmail = document.getElementById('EmailId Field');
var len = strEmail.length;
var i_at = strEmail.indexOf("@");
var i_dot = strEmail.indexOf(".");
var i_space = strEmail.indexOf(" ");
if(len < 5) //a@b.c minimum length
{
alert("please enter your E-mail address");
strEmail.focus();
}
else if(i_at<=0 || i_dot<=0 || i_space!=-1 || i_dot==i_at+1 || i_dot==len-1 || i_at==len-1)
{
alert("please enter a valid Email ID");
strEmail.focus();
}
}
{
// Author: Surendra Sambana
//Purpose: Email validation using java script
// One can improve this using regular expressions.
var strEmail = document.getElementById('EmailId Field');
var len = strEmail.length;
var i_at = strEmail.indexOf("@");
var i_dot = strEmail.indexOf(".");
var i_space = strEmail.indexOf(" ");
if(len < 5) //a@b.c minimum length
{
alert("please enter your E-mail address");
strEmail.focus();
}
else if(i_at<=0 || i_dot<=0 || i_space!=-1 || i_dot==i_at+1 || i_dot==len-1 || i_at==len-1)
{
alert("please enter a valid Email ID");
strEmail.focus();
}
}
JavaScript Numeric field Validation
function validate_Numeric()
{
//Author: Surendra Sambana
//Purpose: This function validates a Numeric field
var num = document.getElementById('Numeri Field ID');
var len = num.length;
var i = 0;
while(i< len)
{
i++;
if(num.charAt(i)<=0 || str.charAt(i)>=9)
{
alert("Please enter a valid numeric");
}
}
}
{
//Author: Surendra Sambana
//Purpose: This function validates a Numeric field
var num = document.getElementById('Numeri Field ID');
var len = num.length;
var i = 0;
while(i< len)
{
i++;
if(num.charAt(i)<=0 || str.charAt(i)>=9)
{
alert("Please enter a valid numeric");
}
}
}
JavaScript Convert Char to Ascii
function ToAscii(characher)
{
//Author: Surendra Sambana
//Purpose: This function returns Ascii value of a given char.
var counter;
for (counter = 0; counter< 256; ++ counter)
{
var to_hexa = counter.toString (16);
if (to_hexa . length == 1)
to_hexa = "0" + to_hexa;
to_hexa = "%" + to_hexa;
to_hexa = unescape (to_hexa);
if (to_hexa == characher)
break;
}
return counter;
}
{
//Author: Surendra Sambana
//Purpose: This function returns Ascii value of a given char.
var counter;
for (counter = 0; counter< 256; ++ counter)
{
var to_hexa = counter.toString (16);
if (to_hexa . length == 1)
to_hexa = "0" + to_hexa;
to_hexa = "%" + to_hexa;
to_hexa = unescape (to_hexa);
if (to_hexa == characher)
break;
}
return counter;
}
JavaScript Alpha Numetric field Validation
function Validate_AlphaNumeric()
{
//Author: Surendra Sambana
var strToValidate = '*';
var j=0;
while(j < strToValidate.length)
{
if((97 <= ToAscii(strToValidate.charAt(j)))&&(ToAscii(strToValidate.charAt(j)) <= 122) || (ToAscii(strToValidate.charAt(j)) >= 48)&&(ToAscii(strToValidate.charAt(j)) < 57))
{
// Please change If statement if u want to eliminate else part
}
else
{
alert("please enter a valid Alpha Numeric value");
break;
}
j++;
}
}
{
//Author: Surendra Sambana
var strToValidate = '*';
var j=0;
while(j < strToValidate.length)
{
if((97 <= ToAscii(strToValidate.charAt(j)))&&(ToAscii(strToValidate.charAt(j)) <= 122) || (ToAscii(strToValidate.charAt(j)) >= 48)&&(ToAscii(strToValidate.charAt(j)) < 57))
{
// Please change If statement if u want to eliminate else part
}
else
{
alert("please enter a valid Alpha Numeric value");
break;
}
j++;
}
}
JavaScript Required Field Validation
function Validate_RequiredField()
{
//Author : Surendra Sambana
var fieldToValidate = " ";
if(fieldToValidate.Trim() == null || fieldToValidate.Trim().length < 1)
alert("Please enter value")
alert(fieldToValidate.Trim().length );
}
{
//Author : Surendra Sambana
var fieldToValidate = " ";
if(fieldToValidate.Trim() == null || fieldToValidate.Trim().length < 1)
alert("Please enter value")
alert(fieldToValidate.Trim().length );
}
DataSet Vs SqlDataReader
DataSet
DataSet object will be populated by a SqlDataAdapter object.Below are the requirements where DataSet is more appropriate.
1.When you require a disconnected in memory of data.
where you can pass it to another tier/layer of your application.
2.Where we require an in-memory relational view of the data.(when you retrieve data from multiple tables/sources, you can have relations between DataBase objects in DataSet.)
3.SqlDataAdapter provides batch update mechanism.
4.When you want to perform data binding with a control that supports a data source that implements IList.
Notes:
1.SqlDataAdapter automatically handles the connection open and close.
2.If you open the connection, SqlDataAdapter won't close it for you. it is developer responsibility to close the connection.
I guess SqlDataAdapter won't bother about the connection that you opened. it just picks another connection from the pool and uses it and closes once its done. The connection that you opened explicitly is your baby so you need to take care about it.
SqlDataReader
SqlDataReader object will be created by calling the ExecuteReader method of the
SqlCommand object.
Below are the scenarios where DataReader is appropriate
1.When you are dealing with large volumes of data, Where its tough to maintain in a single cache.
2.When you want to avoid the object creation(DataSet, DataTable, Rowcolection etc) overhead associated with the DataSet.
3.When you want to perform data binding with a control that supports a data source that implements IEnumerable.
Note: The SqlDataAdapter internally uses SqlDataReader to populate data into DataSe/DataTable.
Here are some difference in table format.
DataSet object will be populated by a SqlDataAdapter object.Below are the requirements where DataSet is more appropriate.
1.When you require a disconnected in memory of data.
where you can pass it to another tier/layer of your application.
2.Where we require an in-memory relational view of the data.(when you retrieve data from multiple tables/sources, you can have relations between DataBase objects in DataSet.)
3.SqlDataAdapter provides batch update mechanism.
4.When you want to perform data binding with a control that supports a data source that implements IList.
Notes:
1.SqlDataAdapter automatically handles the connection open and close.
2.If you open the connection, SqlDataAdapter won't close it for you. it is developer responsibility to close the connection.
I guess SqlDataAdapter won't bother about the connection that you opened. it just picks another connection from the pool and uses it and closes once its done. The connection that you opened explicitly is your baby so you need to take care about it.
SqlDataReader
SqlDataReader object will be created by calling the ExecuteReader method of the
SqlCommand object.
Below are the scenarios where DataReader is appropriate
1.When you are dealing with large volumes of data, Where its tough to maintain in a single cache.
2.When you want to avoid the object creation(DataSet, DataTable, Rowcolection etc) overhead associated with the DataSet.
3.When you want to perform data binding with a control that supports a data source that implements IEnumerable.
Note: The SqlDataAdapter internally uses SqlDataReader to populate data into DataSe/DataTable.
Here are some difference in table format.
DataReader | DataSet |
A DataReader is specific to a data provider (for example, SqlDataReader, OdbcDataReader, and OleDbDataReader). | The DataSet class isn’t a part of any data provider. It’s specific to .NET only. However, the DataAdapter used to fill the DataSet with Fill() is specific to a data provider. |
The data retrieved through a DataReader is read-only. | The data retrieved through a DataSet is read-write. |
The data retrieved through a DataReader is forward-only. Once the data has been cycled through, the DataReader must be closed and re-created in order to reaccess the data. | You can work with data in a DataSet in any order you choose as many times as you like. |
A DataReader presents data through a direct connection to the data source. Only one row of data is stored in Internet Information Services (IIS) memory at any one time. | A DataSet stores all the data from the data source in IIS memory at once. |
A DataReader is fast. | A DataSet is slower than a DataReader. |
A DataReader takes up few IIS and memory resources but annexes the databaseconnection until it’s closed. | A DataSet takes up a lot more memory/IIS resources to store all the data, but it doesn’t hold up a database connection until it’s closed. The connection needs to be open only when Fill() is called. |
A DataReader lasts as long as the connection to the database is open. It can’t be persisted in a cookie or a session variable. | A DataSet lasts only until the page is reloaded (posted back) unless it’s somehow persisted (for example, in a session variable). |
Fields in a DataReader are referenced by index number or name. | You can reference fields in a DataSet by name, but you must also name the DataTable and identify the row (index) that contains the field. |
A DataReader has no concept of primary keys, constraints, views, or any other relational database management system (RDBMS) concept except row and field. | A DataSet contains DataTables. A primary key may be set for each DataTable, and relationships and constraints may be established between them. DataViews may be created over the DataSet. |
You can’t update a data source through a DataReader. | You can make changes to data in a DataSet and then upload those changes back to the data source. |
A DataReader connects to only onedata source. | A DataSet can be filled with Fill() from multiple data sources. |
Stored Procedures vs. Direct SQL
Stored procedures generally result in improved performance because the database can optimize the data access plan used by the procedure and cache it for subsequent reuse
Stored procedures can be individually secured within the database. A client can be granted permissions to execute a stored procedure without having any permissions on the underlying tables.
Stored procedures result in easier maintenance because it is generally easier to modify a stored procedure than it is to change a hard-coded SQL statement within a deployed component.
Stored procedures add an extra level of abstraction from the underlying database schema. The client of the stored procedure is isolated from the implementation details of the stored procedure and from the underlying schema.
Stored procedures can reduce network traffic, because SQL statements can be executed in batches rather than sending multiple requests from the client.
Stored procedures can be individually secured within the database. A client can be granted permissions to execute a stored procedure without having any permissions on the underlying tables.
Stored procedures result in easier maintenance because it is generally easier to modify a stored procedure than it is to change a hard-coded SQL statement within a deployed component.
Stored procedures add an extra level of abstraction from the underlying database schema. The client of the stored procedure is isolated from the implementation details of the stored procedure and from the underlying schema.
Stored procedures can reduce network traffic, because SQL statements can be executed in batches rather than sending multiple requests from the client.
Subscribe to:
Posts (Atom)