在我的网络应用程序中,我有一个搜索框,以便我可以使用名字或姓氏搜索我的数据库,它将在我的网络应用程序中显示结果。用户输入名字或姓氏。使用 Like 查询..如何编写 Like 查询这个查询。
public DataTable SearchbyOPDname(string fname, string lname)
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
string sql = "SELECT opd_id AS [OPD No], opd_date AS DATE, opd_dpt AS DEPARTMENT,
opd_pfname AS [FIRST NAME], opd_plname AS [LAST NAME], opd_age AS AGE, opd_gender AS GENDER,
opd_mob AS [MOBILE NO], opd_fthrname AS [FATHER NAME], opd_hsbndname AS [HUSBAND NAME]
FROM tbl_OPD WHERE opd_pfname like'" + fname +"' OR opd_plname like'" + lname + "'ORDER BY DATE DESC";
SqlDataAdapter adp = new SqlDataAdapter(sql, con);
DataTable dt = new DataTable();
adp.Fill(dt);
con.Close();
return dt;
}