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

Wednesday, April 29, 2009

MVM from DotnetSpider.com

Its a very cool Morning today. I got a call from Gaurav Arora informing me that I got the MVM Award and then foolwed by a mail from Raghav , The webmaster of http//:dotnetspider.com regarding the Most Valuable Member award from Dotnetspider. This is the moment of my dreams come true. Here are the few lines from the mail :

Congratulations from dotnetspider.com! Your contributions to the technology world is recognized by dotnetspider.com, one of the most respected technology community. We are glad to inform you that you are selected as the MOST VALUABLE MEMBER (MVM) for your active participation and contribution to dotnetspider.com. You will be awarded with a certificate of appreciation from us.Visit this page for the list of winners - http://www.dotnetspider.com/credits/Index.aspx
and you can catch the annoucment at
http://www.dotnetspider.com/forum/203217-Winners-MVM-award.aspx

My thanks to DNS family for this award and special thanks to Raghav who showed the faith in me and to Gaurav Arora who have nominated me for this prestigious award.

Subscribe via email

Enter your email address:

Delivered by FeedBurner

MSDotnetMentor

MSDotnetMentor My Website http://msdotnetmentor.com