protected void Button1_Click(object sender, EventArgs e)
{
MySqlConnection connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["myconstring"].ConnectionString);
connection.Open();
symptons = String.Join(", ", CheckBoxList1.Items.Cast<ListItem>().Where(i => i.Selected).Select(i => i.Value).ToArray());
Label3.Text = symptons;
if(symptons!="")
{
MySqlCommand cmd = new MySqlCommand("select d.dname from disease d inner join diseasesymptom ds on ds.did = d.did inner join symptom s on s.sid = ds.sid where s.sname in (" + symptons + ")", connection);
using (MySqlDataAdapter sda = new MySqlDataAdapter())
{
cmd.Connection = connection;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
else
{
Label2.Text = "select at least one symptom";
}
}
I know I'm sort of performing sql injection on my own code so how can i prevent this, there are basically 3 tables:
- disease_table [columns=] (disease_id,disease_name)
- symptom_table [columns=] (symptom_id,symptom_name)
- disease_symptom [columns=] (disease_id,symptom_id)
there is a checkboxlist on my web page which has symptoms where text=fever, value='fever'..and so on reason for doing this was that the users could select any number of checkboxes and in clause doesn't accept parameters