SqlDataAdapter da =
new SqlDataAdapter("SELECT *
FROM Patient
Where Registration_Id = '" + textBox1.Text + "'
OR Patient_Name = '" + textBox1.Text + "'", cn);
How to search int or string in all fields?
Edit code:
if (comboBox1.Text == "Registration_Id")
{
da = new SqlDataAdapter("SELECT *
FROM Patient
Where Registration_Id = '" + textBox1.Text + "'", cn);
}
else if (comboBox1.Text == "Patient_Name")
{
da = new SqlDataAdapter("SELECT *
FROM Patient
Where Patient_Name = '" + textBox1.Text + "'", cn);
}
}
else if (comboBox1.Text == "Patient_Name")
{
da = new SqlDataAdapter("SELECT * FROM Patient Where Patient_Name = '" + textBox1.Text + "'", cn);
}
< - Kazim King 2012-04-04 18:13
For one that method can be subject to SQL injection attack so you need to sanitize it. Otherwise one solution (after you check for attacks) is:
SELECT *
FROM Patient
Where column1 like "'%" + textBox1.Text + "%'"
or column2 like "'%" + textBox1.Text + "%'"
......
or columnn like "'%" + textBox1.Text + "%'"
This can be made simpler by the fact that if they don't know the id of the item then don't check that column. Otherwise have a dropdown that chooses which column they are searching by.