string email = txtEmail.Text.ToString();
string pattern = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|" + @"0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z]" + @"[a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";
System.Text.RegularExpressions.Match match = Regex.Match(email, pattern, RegexOptions.IgnoreCase);
if (match.Success)
{
}
Else
{
{
MessageBox.Show("Don't Leave the Field Empty", "Name Entry Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
http://royalarun.blogspot.com/2010/09/e-mail-validation-using-regex.html
Option Explicit statement and Option Strict Statement
Option Explicit Statement
The Option Explicit has two modes. On and Off mode.
If Option Explicit mode in ON , you have to declare all the variable before you use it in the program . If not , it will generate a compile-time error whenever a variable that has not been declared is encountered .If the Option Explicit mode is OFF , Vb.Net automatically create a variable whenever it sees a variable without proper declaration.
By default the Option Explicit is On
Option Strict Statement
Visual Basic allows conversions of many data types to other data types. Data loss can occur when the value of one data type is converted to a data type with less precision or smaller capacity. A run-time error occurs if such a narrowing conversion fails. Option Strict ensures compile-time notification of these narrowing conversions so they can be avoided.
On
Optional. Enables Option Strict checking.
Off
Optional. Disables Option Strict checking. If On or Off is not specified, the default is Off.
The Option Explicit has two modes. On and Off mode.
If Option Explicit mode in ON , you have to declare all the variable before you use it in the program . If not , it will generate a compile-time error whenever a variable that has not been declared is encountered .If the Option Explicit mode is OFF , Vb.Net automatically create a variable whenever it sees a variable without proper declaration.
By default the Option Explicit is On
Option Strict Statement
Visual Basic allows conversions of many data types to other data types. Data loss can occur when the value of one data type is converted to a data type with less precision or smaller capacity. A run-time error occurs if such a narrowing conversion fails. Option Strict ensures compile-time notification of these narrowing conversions so they can be avoided.
On
Optional. Enables Option Strict checking.
Off
Optional. Disables Option Strict checking. If On or Off is not specified, the default is Off.
Commonly used interfaces in .Net
Class Description
IComparable
-----------
Implemented by types whose values can be ordered; for example, the numeric and string classes. IComparable is required for sorting.
IDisposable
-----------
Defines methods for manually disposing of an object. This interface is important for large objects that consume resources, or objects that lock access to resources such as databases.
IConvertible
------------
Enables a class to be converted to a base type such as Boolean,Byte, Double, or String.
ICloneable
----------
Supports copying an object.
IEquatable
----------
Allows you to compare to instances of a class for equality. For example, if you implement this interface, you could say “if (a == b)”.
IFormattable
------------
Enables you to convert the value of an object into a specially formatted string. This provides greater flexibility than the base ToString method.
IComparable
-----------
Implemented by types whose values can be ordered; for example, the numeric and string classes. IComparable is required for sorting.
IDisposable
-----------
Defines methods for manually disposing of an object. This interface is important for large objects that consume resources, or objects that lock access to resources such as databases.
IConvertible
------------
Enables a class to be converted to a base type such as Boolean,Byte, Double, or String.
ICloneable
----------
Supports copying an object.
IEquatable
----------
Allows you to compare to instances of a class for equality. For example, if you implement this interface, you could say “if (a == b)”.
IFormattable
------------
Enables you to convert the value of an object into a specially formatted string. This provides greater flexibility than the base ToString method.
Generics in .Net Framework
Used to Reduced run-time errors,The compiler cannot detect type errors when you cast
to and from the Object class.the runtime will throw an exception
Using generics allows the compiler to catch this type of bug before your program runs
Generics improves runtime Performance.
Eg:
// Add a double and an int using the Obj class
Obj ob = new Obj(10.125, 2005);
Console.WriteLine((double)ob.t + (int)ob.u);
// Add a double and an int using the Gen class
Gen gb = new Gen(10.125, 2005);
Console.WriteLine(gb.t + gb.u);
If you run that code in a console application, the Obj and Gen classes produce exactly
the same results. However, the code that uses the Gen class actually works faster
because it does not require boxing and unboxing to and from the Object class.
to and from the Object class.the runtime will throw an exception
Using generics allows the compiler to catch this type of bug before your program runs
Generics improves runtime Performance.
Eg:
// Add a double and an int using the Obj class
Obj ob = new Obj(10.125, 2005);
Console.WriteLine((double)ob.t + (int)ob.u);
// Add a double and an int using the Gen class
Gen gb = new Gen(10.125, 2005);
Console.WriteLine(gb.t + gb.u);
If you run that code in a console application, the Obj and Gen classes produce exactly
the same results. However, the code that uses the Gen class actually works faster
because it does not require boxing and unboxing to and from the Object class.
What is the basic difference between Dataset and Typed Dataset ? When would you use Typed dataset?
Typed DataSet is precompiled one
For Example in Normal DataSet this is how we use to get data.
ds.Tables["Employee"].Rows[0][0]
In typed DataSet usage is strongly bound.
ds.EmployeeTable.Rows[0].EmpIdColumn
Here every thing is typed no need to use index/name to identify table or column name.
Typed dataset yields less errors than mornal dataset in all the way.
Typed Dataset is faster than the normal dataset .
Typed DataSet
// C#
// This accesses the CustomerID column in the first row of
// the Customers table.
string s;
s = dsCustomersOrders1.Customers[0].CustomerID;
Untyped Datasets
// C#
string s = (string) dsCustomersOrders1.Tables["Customers"].Rows[0]["CustomerID"];
In addition to being easier to work with, the syntax for the typed dataset provides type checking at compile time, greatly reducing the possibility of errors in assigning values to dataset members
The problem of typed dataset is dynamic behaviour
For Example in Normal DataSet this is how we use to get data.
ds.Tables["Employee"].Rows[0][0]
In typed DataSet usage is strongly bound.
ds.EmployeeTable.Rows[0].EmpIdColumn
Here every thing is typed no need to use index/name to identify table or column name.
Typed dataset yields less errors than mornal dataset in all the way.
Typed Dataset is faster than the normal dataset .
Typed DataSet
// C#
// This accesses the CustomerID column in the first row of
// the Customers table.
string s;
s = dsCustomersOrders1.Customers[0].CustomerID;
Untyped Datasets
// C#
string s = (string) dsCustomersOrders1.Tables["Customers"].Rows[0]["CustomerID"];
In addition to being easier to work with, the syntax for the typed dataset provides type checking at compile time, greatly reducing the possibility of errors in assigning values to dataset members
The problem of typed dataset is dynamic behaviour
Difference between Int32.Parse,Convert.Int32
Int32.Parse Method:
-------------------
Converts the string representation of a number to its 32-bit signed integer equivalent.
-When s is a null reference, it will throw ArgumentNullException.
-If s is other than integer value, it will throw FormatException.
-When s represents a number out of range, it will throw OverflowException.
Convert.ToInt32(string):
-------------------------
Converts the specified string representation of 32-bit signed integer equivalent. This calls in turn Int32.Parse () method.
-When s is a null reference, it will return 0 rather than throw ArgumentNullException.
-If s is other than integer value, it will throw FormatException.
-When s represents a number out of range, it will throw OverflowException.
Int32.TryParse Method:
----------------------
Converts the specified string representation of 32-bit signed integer equivalent to out variable, and returns true if it is parsed successfully, false otherwise.
-When s is a null reference, it will return 0.
-If s is other than an integer value, the out variable will have 0.
-When s represents a number out of range, the out variable will have 0
Int32.parse(string)
Int32.Parse (string s)
string s1 = "1234";
string s2 = "1234.65";
string s3 = null;
string s4 = "123456789123456789123456789123456789123456789";
int result;
bool success;
result = Int32.Parse(s1); //-- 1234
result = Int32.Parse(s2); //-- FormatException
result = Int32.Parse(s3); //-- ArgumentNullException
result = Int32.Parse(s4); //-- OverflowException
Convert.ToInt32(string)
For example:
result = Convert.ToInt32(s1); //-- 1234
result = Convert.ToInt32(s2); //-- FormatException
result = Convert.ToInt32(s3); //-- 0
result = Convert.ToInt32(s4); //-- OverflowException
success = Int32.TryParse(s1, out result); //-- success => true; result => 1234
success = Int32.TryParse(s2, out result); //-- success => false; result => 0
success = Int32.TryParse(s3, out result); //-- success => false; result => 0
success = Int32.TryParse(s4, out result); //-- success => false; result => 0
-------------------
Converts the string representation of a number to its 32-bit signed integer equivalent.
-When s is a null reference, it will throw ArgumentNullException.
-If s is other than integer value, it will throw FormatException.
-When s represents a number out of range, it will throw OverflowException.
Convert.ToInt32(string):
-------------------------
Converts the specified string representation of 32-bit signed integer equivalent. This calls in turn Int32.Parse () method.
-When s is a null reference, it will return 0 rather than throw ArgumentNullException.
-If s is other than integer value, it will throw FormatException.
-When s represents a number out of range, it will throw OverflowException.
Int32.TryParse Method:
----------------------
Converts the specified string representation of 32-bit signed integer equivalent to out variable, and returns true if it is parsed successfully, false otherwise.
-When s is a null reference, it will return 0.
-If s is other than an integer value, the out variable will have 0.
-When s represents a number out of range, the out variable will have 0
Int32.parse(string)
Int32.Parse (string s)
string s1 = "1234";
string s2 = "1234.65";
string s3 = null;
string s4 = "123456789123456789123456789123456789123456789";
int result;
bool success;
result = Int32.Parse(s1); //-- 1234
result = Int32.Parse(s2); //-- FormatException
result = Int32.Parse(s3); //-- ArgumentNullException
result = Int32.Parse(s4); //-- OverflowException
Convert.ToInt32(string)
For example:
result = Convert.ToInt32(s1); //-- 1234
result = Convert.ToInt32(s2); //-- FormatException
result = Convert.ToInt32(s3); //-- 0
result = Convert.ToInt32(s4); //-- OverflowException
success = Int32.TryParse(s1, out result); //-- success => true; result => 1234
success = Int32.TryParse(s2, out result); //-- success => false; result => 0
success = Int32.TryParse(s3, out result); //-- success => false; result => 0
success = Int32.TryParse(s4, out result); //-- success => false; result => 0
The using keyword has two major uses:
As a directive, when it is used to create an alias for a namespace or to import types defined in other namespaces. See using Directive.
As a statement, when it defines a scope at the end of which an object will be disposed. See using Statement.
Using 'using'
A typical scenario where we could use the using statement is :
Collapse
string connString = "Data Source=localhost;Integrated " +
"Security=SSPI;Initial Catalog=Northwind;";
using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT ID, Name FROM Customers";
conn.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
Console.WriteLine("{0}\t{1}", dr.GetString(0), dr.GetString(1));
}
}
Note
The using statement is only useful for objects with a lifetime that does not extend beyond the method in which the objects are constructed. Remember that the objects you instantiate must implement the System.IDisposable interface.
There is no equivalent for the using statement in vb.net. You have to use the try finally block.
As a statement, when it defines a scope at the end of which an object will be disposed. See using Statement.
Using 'using'
A typical scenario where we could use the using statement is :
Collapse
string connString = "Data Source=localhost;Integrated " +
"Security=SSPI;Initial Catalog=Northwind;";
using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT ID, Name FROM Customers";
conn.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
Console.WriteLine("{0}\t{1}", dr.GetString(0), dr.GetString(1));
}
}
Note
The using statement is only useful for objects with a lifetime that does not extend beyond the method in which the objects are constructed. Remember that the objects you instantiate must implement the System.IDisposable interface.
There is no equivalent for the using statement in vb.net. You have to use the try finally block.
Generate a report using Crystal Reports in Visual Studio 2010
http://www.codeproject.com/KB/aspnet/Crstalreportusingvs2010.aspx
Subscribe to:
Posts (Atom)