SQL SELECT语句,用于选择特定字段的值并显示所有行

时间:2014-10-01 07:46:14

标签: c# sql

如何通过使用sql查询搜索特定列名来显示完整行的内容?

我试着写这样的查询:

s = "select RegNo, FirstName, LastName,JobTittle,TotalExperienceYear,TotalExperienceMonth,AreaPrefered,MobileNo from EmployeeRegistration where RegNo like '%" + reg + "' or FirstName like '%" + reg + "' or LastName like '%" + reg + "' or JobTittle like '%" + reg + "' or TotalExperienceYear like '%" + reg + "' or TotalExperienceMonth like '%" + reg + "' or AreaPrefered like '%" + reg + "' or MobileNo like '%" + reg + "%'";

但它在不同字段之间看起来相同的值时选择字段。

2 个答案:

答案 0 :(得分:0)

s = "SELECT
RegNo, FirstName, LastName,JobTittle,TotalExperienceYear,TotalExperienceMonth,AreaPrefered,MobileNo 
FROM EmployeeRegistration
WHERE RegNo like '%" + reg + "'";

尝试此查询。您正在检查所有列,但它无法返回一个东西,因为FirstName,LastName,RegNo,JobTitle所有这些东西都不能像'%reg'

答案 1 :(得分:0)

s =“从EmployeeRegistration中选择RegNo,FirstName,LastName,JobTittle,TotalExperienceYear,TotalExperienceMonth,AreaPrefered,MobileNo,FatherName,其中RegNo喜欢'%'+ txtRno.Text +”%'AND FirstName喜欢'%'+ txtFstName.Text +“%'和LastName喜欢'%'+ txtSecondName.Text +”%'和JobTittle喜欢'%'+ TxtJobTittle.Text +“%'和TotalExperienceYear喜欢'%'+ txtExpYear.Text +”%'和TotalExperienceMonth like' %“+ txtExpMonth.Text +”%'和AreaPrefered类似'%'+ txtScndName.Text +“%'和MobileNo类似'%'+ txtMobno.Text +”%'和FatherName类似'%'+ txtFthrName.Text +“ %'“;