从datagridview1中选择数据(行)时,包含数据库中数据的结果将显示在listview1中。 [英] When you select a data(row) from datagridview1 the results that has those data from the database will appear in the listview1.

查看:63
本文介绍了从datagridview1中选择数据(行)时,包含数据库中数据的结果将显示在listview1中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从datagridview1中选择数据(行)时,包含数据库中数据的结果将显示在listview1中。

他们将对所选数据进行过滤和排序。



例如:



- 你选择了一个症状

- 加强

-结果(在疾病名称中)您在datagridview1中选择的咳嗽症状将自动显示在listview1中。

- 您选择另一个症状

-Wheezing
-您在datagridview1中选择的咳嗽和喘息的结果(疾病名称)将自动显示在listview1中,没有这些数据的人将自动消失。



我认为就像你选择那个词一样。他们会在数据库表中找到它。像咳嗽或喘息这个词,甚至只是字母。它会自动在另一个datagridview中显示它。



结果也在数据库中。

他们将在数据库中获取这些数据(MySql)



我打算在数据库中的字典表中获取这些数据。还有一些列,如疾病的名称,原因,症状,治疗等。

但我唯一想从中获取数据的专栏只是症状和疾病的名称。





我真的不知道语法。我真的不知道从哪里开始。请帮忙。非常感谢。我希望你能理解我的问题。 :)



我试过编码吧。 Heheh。但是一切都错了。



我的尝试:



When you select a data(row) from datagridview1 the results that has those data from the database will appear in the listview1.
They will filter and sort the selected data.

For example:

-You select a symptoms
-Coughing
-The results(name of the disease) that has a coughing symptom that you selected in the datagridview1 will automatically display in the listview1.
-You select another symptom
-Wheezing
-The results(name of the disease) that has coughing and wheezing that you selected in the datagridview1 will automatically display in the listview1 and those who doesn't have those data will automatically disappear.

I think it's like when you select that word. They will find it in the database table. Like the word cough or wheezing or even the letters only. And it will automatically display it in another datagridview.

The results are also in the database.
They will get those data in the database(MySql)

I'm planning to just get those data in my dictionary table in database. And there are columns like the name of the disease, causes, symptoms, treating and etc.
But the only column that I just want to get the data from are only symptoms and the name of the disease.


I really don't know the syntax. I really don't know where to start. Please help. Thank you so much. I hope you can understand my question. :)

I tried coding it. Heheh. But everything is just so wrong.

What I have tried:

 private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count != 0)
            {
                con.Open();
                cmd = new SqlCommand(@"Select * from DICTIONARY where Symptoms LIKE '% 
{0}%'", con);
                rdr = cmd.ExecuteReader();
                if (rdr.Read())
                {
                    dataGridView1.Rows.Add(rdr[0].ToString(), rdr[1].ToString());
                }

            List<string> selectedRows = new List<string>();

            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                string currentRow = string.Empty;

                foreach (DataGridViewCell cell in row.Cells)
                {
                    currentRow += String.Format("{0} ", cell.FormattedValue);
                }

                selectedRows.Add(currentRow);
            }

            for (int i = 0; i < selectedRows.Count; i++)
            {
                this.listview1.Items.Add(selectedRows[i]);
            }

            }
        }

推荐答案

您没有添加症状名称进入你的SQL命令。 {0} 构造由 String.Format 使用,并且需要实际的参数名称。对于SQL命令,您应该使用参数化查询。此外,您正在尝试将数据库结果添加到DataGridView而不是ListView。
You are not adding the symptom name into your SQL command. The {0} construct is used by String.Format and requires the actual parameter name. For SQL commands you should use parameterised queries. Also, you are trying to add the database results to the DataGridView instead of the ListView.


这篇关于从datagridview1中选择数据(行)时,包含数据库中数据的结果将显示在listview1中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆