Lets cheers, its a good news for all Microsoft lovers.
Microsoft TechEd2009 will be conducting in Hyderabad from May13 to May15.
Main attention of the eve is Steven A. Ballmer,CEO Microsoft. This is the greatest and biggest eve in India and expecting to see a huge crowd from developer community.
To grab more details please visit : Microsoft TechEd2009.
Sunday, May 3, 2009
Thursday, April 30, 2009
Using enum Search Database
Using enum Search Database
This example demonstrates the use of enum.
How this enum is used to set the way to fecth data from the database
Declaring enum
/// this enum will define in which way the search should be made
/// all stats that the parameter should exactly match
/// start states that the vlaue passed should be serched for any value starting with
/// End states that the vlaue passed should be serched for any value ending with
/// Middle states that the vlaue passed should be serched for any value which conatins these charates any where
///
public enum SearchDirection
{
All=0,
Start=1,
End=2,
Middle=3
}
Declaring and Defining the function
///
/// Checks the Field Value whether exist in database or not
///
/// Value to check for
/// Value to check in which field
/// Value to Check in which Table
/// Specifies the search direction
///
public Int32 CheckFieldValue(String fldValue, String fldName,String TblName,SearchDirection SearchDir)
{
String strquery = "";
String str=Enum.GetName(typeof(SearchDirection),SearchDir);
if(((Int32)Enum.Parse(typeof(SearchDirection),str))==0)
{
strquery = "select * from " + TblName + " where " + fldName + " ='" + fldValue + "'";
}
else if (((Int32)Enum.Parse(typeof(SearchDirection), str)) == 1)
{
strquery = "select * from " + TblName + " where " + fldName + " like'" + fldValue + "%'";
}
else if (((Int32)Enum.Parse(typeof(SearchDirection), str)) == 2)
{
strquery = "select * from " + TblName + " where " + fldName + " like'%" + fldValue + "'";
}
else if (((Int32)Enum.Parse(typeof(SearchDirection), str)) == 3)
{
strquery = "select * from " + TblName + " where " + fldName + " like'%" + fldValue + "%'";
}
SqlConnection DBConnection = new SqlConnection();
SqlCommand DBCommand = new SqlCommand();
if (DBConnection.State == ConnectionState.Closed)
{
DBConnection.ConnectionString = "yourConnectionString";
DBConnection.Open();
}
DBCommand.Connection = DBConnection;
DBCommand.CommandText = strquery;
Int32 i=DBCommand.ExecuteNonQuery();
DBConnection.Close();
return i;
}
++
Thanks and Regards
Meetu Choudhary
http://msdotnetmentor.com
This example demonstrates the use of enum.
How this enum is used to set the way to fecth data from the database
Declaring enum
/// this enum will define in which way the search should be made
/// all stats that the parameter should exactly match
/// start states that the vlaue passed should be serched for any value starting with
/// End states that the vlaue passed should be serched for any value ending with
/// Middle states that the vlaue passed should be serched for any value which conatins these charates any where
///
public enum SearchDirection
{
All=0,
Start=1,
End=2,
Middle=3
}
Declaring and Defining the function
///
/// Checks the Field Value whether exist in database or not
///
/// Value to check for
/// Value to check in which field
/// Value to Check in which Table
/// Specifies the search direction
///
public Int32 CheckFieldValue(String fldValue, String fldName,String TblName,SearchDirection SearchDir)
{
String strquery = "";
String str=Enum.GetName(typeof(SearchDirection),SearchDir);
if(((Int32)Enum.Parse(typeof(SearchDirection),str))==0)
{
strquery = "select * from " + TblName + " where " + fldName + " ='" + fldValue + "'";
}
else if (((Int32)Enum.Parse(typeof(SearchDirection), str)) == 1)
{
strquery = "select * from " + TblName + " where " + fldName + " like'" + fldValue + "%'";
}
else if (((Int32)Enum.Parse(typeof(SearchDirection), str)) == 2)
{
strquery = "select * from " + TblName + " where " + fldName + " like'%" + fldValue + "'";
}
else if (((Int32)Enum.Parse(typeof(SearchDirection), str)) == 3)
{
strquery = "select * from " + TblName + " where " + fldName + " like'%" + fldValue + "%'";
}
SqlConnection DBConnection = new SqlConnection();
SqlCommand DBCommand = new SqlCommand();
if (DBConnection.State == ConnectionState.Closed)
{
DBConnection.ConnectionString = "yourConnectionString";
DBConnection.Open();
}
DBCommand.Connection = DBConnection;
DBCommand.CommandText = strquery;
Int32 i=DBCommand.ExecuteNonQuery();
DBConnection.Close();
return i;
}
++
Thanks and Regards
Meetu Choudhary
http://msdotnetmentor.com
Subscribe to:
Posts (Atom)
Subscribe via email
MSDotnetMentor
MSDotnetMentor
My Website
http://msdotnetmentor.com