如何修复listview和mysql重复?

oalqel3c  于 2021-06-19  发布在  Mysql
关注(0)|答案(0)|浏览(212)

我创建了一个包含我的数据库的listview,但是每次我按“列出它”,它都会在listview中重复。你知道怎么解决吗?我填充文本框来提交信息,这在listview中是看不到的。有提交的代码;

private void button1_Click(object sender, EventArgs e)
    {
        keko.Open();
        cmd = new MySqlCommand("Insert into calisanlist(Adı,Soyadı,Yevmiye) values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')", keko);
        cmd.ExecuteNonQuery();
        keko.Close();
        textBox1.Clear();
        textBox2.Clear();
        textBox3.Clear();

这里有列出它的代码;

private void verilerigoruntule()
    {

        keko.Open();
        MySqlCommand cmd = new MySqlCommand("Select * from calisanlist", keko);
        MySqlDataReader gr = cmd.ExecuteReader();

        while(gr.Read())
        {
            ListViewItem ekle = new ListViewItem();
            ekle.Text = gr["Adı"].ToString();
            ekle.SubItems.Add(gr["Soyadı"].ToString());
            ekle.SubItems.Add(gr["Yevmiye"].ToString());
            ekle.SubItems.Add(gr["Gun"].ToString());
            ekle.SubItems.Add(gr["Maaş"].ToString());

            listView1.Items.Add(ekle);

        }
        keko.Close();

 private void button2_Click(object sender, EventArgs e)
    {
        verilerigoruntule();

    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题