首页 > 解决方案 > 通过datagridview中的选定行使用第二种形式更改数据库表

问题描述

我的第一个表单中有一个 DataGridView,我制作了第二个表单来使用以下代码创建一个数据库条目:

    clsMSSQL.clsMSSQL ticket = new clsMSSQL.clsMSSQL(5);
    string query = "INSERT INTO ticket.support (Betreff, Problembeschreibung, Kategorie, Ersteller, Bearbeiter, E-Mail, Abteilung) " +
       "Values('" + textBox1.Text + "', '" + textBox2.Text + "', '" + comboBox1.Text + "', '" + textBox4.Text + "', '" + textBox5.Text + "', '" + textBox8.Text + "', '" + comboBox3.Text + "')";
    ticket.Query(query);
    ticket.Close();
    myDGW.Refresh();
    this.Close();

现在我制作了第三种形式,它应该能够从第一种形式中获取选定的行并使用文本框更改值。

我试过这个:

    clsMSSQL.clsMSSQL ticket = new clsMSSQL.clsMSSQL(5);
    string query = "UPDATE ticket.support SET = (Betreff, Problembeschreibung, Kategorie, Ersteller, Bearbeiter, E-Mail, Abteilung) " +
       "Values('" + textBox1.Text + "', '" + textBox2.Text + "', '" + comboBox1.Text + "', '" + textBox4.Text + "', '" + textBox5.Text + "', '" + textBox8.Text + "', '" + comboBox3.Text + "') WHERE id='" + dataGridView1.Rows[i].Cells[11].Value.ToString() + "'";
    ticket.Query(query);
    ticket.Close();
    myDGW.Refresh();
    this.Close();

但它不起作用。

标签: c#winformsdatagridview

解决方案


推荐阅读