requete sql via odbc "la propriété connection n'a pas été initialisée ."
Salut !
J'ai un soucis pour faire un insert sur une bdd mssql 2005 via odbc
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| public void button3_Click(object sender, EventArgs e)
{
OdbcConnection connection = new System.Data.Odbc.OdbcConnection("DSN=" + textBox2.Text + ";UID="+textBox3.Text+";PWD="+textBox4.Text+";");
connection.CreateCommand();
OdbcCommand myCommand = new OdbcCommand("INSERT INTO [table] VALUES " + textBox7.Text + " , connection");
try
{
connection.Open();
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
} |
Voici l'erreur :
Citation:
ExecuteNonQuery : la propriété connection n'a pas été initialisée .