我正在开发一个项目,用户在该项目中显示带有热点的图像。单击一个部件后,将显示一个动态生成的复选框,从数据库中选取值(热点将映射到显示的值)。
我面临的问题是,当值是一个单词(例如肿胀)时,代码可以正常工作并获取可能的疾病,但是当有类似的词时(例如关节疼痛或恶心呕吐)即包含它们之间的空格(多于一个单词作为复选框值)代码不起作用。
这是代码
protected void Button2_Click(object sender, EventArgs e)
{
if (TextBox2.Text != "")
{
connection.Open();
symptons = String.Join(", ", CheckBoxList1.Items.Cast<ListItem>().Where(i => i.Selected).Select(i => i.Text).ToArray());
Label1.Text = symptons;
string query = symptons.Replace(", ", "','");
string cm = "select distinct 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 ('" + query + "')" + "and days >" + TextBox2.Text + " and days<41 order by (days) desc;";
if (symptons != "")
{
MySqlCommand cmd = new MySqlCommand(cm, connection);
using (MySqlDataAdapter sda = new MySqlDataAdapter())
{
cmd.Connection = connection;
sda.SelectCommand = cmd;
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
else
{
Label1.Text = "select at least one symptom";
}
}
else
{
string script = "alert(\"We can't predict without all inputs :(\");";
ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true);
}
}
我认为它与我正在执行的加入和替换有关。
答案 0 :(得分:0)