Click here to Skip to main content
15,303,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've made one Form to create a database entry.

Code:

private void button10_Click(object sender, EventArgs e)
{
    clsMSSQL.clsMSSQL ticket = new clsMSSQL.clsMSSQL(5);
    string query = "INSERT INTO ticket.support (titel, beschreibung, kategorie, ersteller, bearbeiter, email, abteilung) " +
       "Values('" + textBox1.Text + "', '" + textBox2.Text + "', '" + comboBox1.Text + "', '" + textBox4.Text + "', '" + textBox5.Text + "', '" + textBox8.Text + "', '" + comboBox3.Text + "')";
    ticket.Query(query);
    ticket.Close();
    this.Close();
}


now I want to make another form which will be opened by a button on the main form. This form should be able to make changes on the database and should specifically change the selected row in the database sorted by the ID.

but that wouldn't work. And because I try to do that on a second form, the code can't find dataGridView1.

What I have tried:

clsMSSQL.clsMSSQL edit= new clsMSSQL.clsMSSQL(5);
string pSQL = "UPDATE INTO ticket.support WHERE id='" + dataGridView1.Rows[i].Cells[11].Value.ToString() + "'";

clsMSSQL.ExecuteCommand(pSQL);
Posted
Updated 31-Mar-21 6:12am

1 solution

Quote:
And because I try to do that on a second form, the code can't find dataGridView1.

Refer to this series of tips on how to pass information between forms Transferring information between two forms, Part 1: Parent to Child[^]
C#
string query = "INSERT INTO ticket.support (titel, beschreibung, kategorie, ersteller, bearbeiter, email, abteilung) " +
       "Values('" + textBox1.Text + "', '" + textBox2.Text + "', '" + comboBox1.Text + "', '" + textBox4.Text + "', '" + textBox5.Text + "', '" + textBox8.Text + "', '" + comboBox3.Text + "')";
You are using string concatenation to create your query. Don't do that. Refer SQL Injection | OWASP[^] and use parameterised queries
   
Comments
Maciej Los 1-Apr-21 3:53am
   
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900