mysql参数传递没有实现asp.net

时间:2016-02-11 14:58:42

标签: c# mysql asp.net

我有3个表1> disease_table [columns =](disease_id,disease_name)2> symptom_table [columns =](symptom_id,symptom_name)3> disease_symptom [columns =](disease_id,symptom_id) 我的网页上有一个复选框列表,其中有text = fever,value ='fever'等症状,但问题是当我将参数传递给sql stmt时没有输出,它没有给出任何输出。如果我传递静态参数(如果我选择传递所有可用的症状),它会给我重复的疾病名称。

这是我的代码:

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 = symptoms;
    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 (@pSymptoms)", connection);
     cmd.Parameters.AddWithValue("@pSymptoms", symptoms);
    using (MySqlDataAdapter sda = new MySqlDataAdapter())
    {
        cmd.Connection = connection;
        sda.SelectCommand = cmd;
        using (DataTable dt = new DataTable())
        {
            sda.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
    }
}

sql stmt:

selectd.name, d.disease_id 
from Disease d
inner join DiseaseSymptom ds on ds.disease_id = d.disease_id
inner join Symptom s on s.symptom_id = ds.symptom_id
where s.name in ('Fever');

输出:如果我传递所有参数(静态),那么我多次得到所有可用的疾病(例如:如果疾病'd1'有2个症状,我选择其中2个症状,疾病'd1'显示两次)< / p>

0 个答案:

没有答案