I'm trying to create a search button that can filter through multiple table columns within a table, I have three seperate codes that can search a data on a particular table column (LastName, FirstName and DriverID):
SqlConnection Con = new SqlConnection();
Con.ConnectionString = "Data Source=PC-PC\\MIKO;
Initial Catalog=Caproj;
Integrated Security=True;";
Con.Open();
string qry = "select LastName from [Driver Table] where LastName=@id";
SqlCommand cmd = new SqlCommand(qry, Con);
cmd.Parameters.AddWithValue("@id", slastname.Text);
cmd.ExecuteNonQuery();
SqlDataAdapter da2 = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da2.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show("Valid Input");
}
else
{
MessageBox.Show("Invalid Input");
}
Is there a way where I can search them all at the same time without the need for making a separate filter for each? Something along the lines of this:
SELECT LastName, FirstName, DriverID
FROM [Driver Table]
WHERE LastName=@id
AND FirstName=@id
AND DriverID=@id