Hi,
Do you want to have a single function where you could send three parameters and get data from the database.
Well in that case just add a class to your asp.net project, write a function with three arguments(just pass the name of the database table,search term, and column to return).
Now on any buttons click you can call this function by either making an onject of this class and calling the function or, having defined the function as static so that you dont have to create an object of the class to call the function.
For example here's a class named clscommon, it has all the functions related to database querying,whenever you like to do something related to databases, just create an object of this class and call the respective function.
public class clsCommon
{
public List<clsComboPrp> GetNameList(String table)
{
List<clsComboPrp> temp = new List<clsComboPrp>();
String myselectquery = "select * from " + table;
MySqlCommand mycommand = new MySqlCommand(myselectquery, con);
mycommand.CommandType = CommandType.Text;
if (con.State == ConnectionState.Open)
con.Close();
con.Open();
MySqlDataReader dr = mycommand.ExecuteReader();
clsComboPrp obj = null;
if (dr.HasRows)
while (dr.Read())
{
obj = new clsComboPrp();
obj.Id = dr[0].ToString();
obj.Name = dr[1].ToString();
temp.Add(obj);
}
dr.Close();
dr.Dispose();
mycommand.Dispose();
con.Close();
return temp;
}
public String GetName(String table, String Id)
{
String name = "";
String query = "select `Name` from `" + table + "` where `ID`=" + Id;
MySqlCommand cmd = new MySqlCommand(query, con);
if (con.State == ConnectionState.Open)
con.Close();
con.Open();
MySqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
name = dr[0].ToString();
}
cmd.Dispose();
con.Close();
return name;
}
Saurabh Nijhawan(B.Tech. CSE,GGSIPU,New Delhi)
Application Architect, Eminent Solutions, New Delhi.
Freelancer | Teacher
Remember to click
"Mark as Answer" on the post, if it helped you.
ASP.NET Webloghttp://www.saurabhnijhawan.comLearning Made Easy