bonjour,
je veux réalisé une requete parametrée j'ai ecris le code suivant :
private void button1_Click(object sender, EventArgs e)
{
Add_informations ma_form_Add_informations = new Add_informations();
{
if (textBox_project_name.Text != "")
{
// Chaîne de connexion
string connectString = @"Data Source=RENNDXPRDL2596\SQLEXPRESS;Initial Catalog=hafid;Integrated Security=True";
// Objet connection
SqlConnection connection = new SqlConnection(connectString);
// Ouverture
connection.Open();
SqlCommand command = new SqlCommand("INSERT INTO [Table_Project]([ID_project],[Project_Category],[kick_off_date],[Location]) VALUES(@ID_project,@Project_Category, @Location, @kick_off_date", connection);
// Paramètres
command.Parameters.Add(new SqlParameter("@ID_project", SqlDbType.NVarChar, 50));
command.Parameters.Add(new SqlParameter("@Project_Category", SqlDbType.NVarChar, 50));
command.Parameters.Add(new SqlParameter("@kick_off_date", SqlDbType.NVarChar, 50));
command.Parameters.Add(new SqlParameter("@Location", SqlDbType.NVarChar, 50));
command.Parameters["@ID_project"].Value = textBox_project_name.Text;
command.Parameters["@Project_Category"].Value = comboBox1.Text;
command.Parameters["@Location"].Value = comboBox2.Text;
command.Parameters["@kick_off_date"].Value = textBox_Date.Text;
// Object datareader
SqlDataReader reader = command.ExecuteReader();
Object[] row = null;
while (reader.Read())
{
if (row == null)
row = new Object[reader.FieldCount];
reader.GetValues(row);
for (int i=0; i<row.GetLength(0); i++)
{
if (row[i] != DBNull.Value)
Console.Write(row[i]);
else
Console.Write("NULL");
if (i<row.GetUpperBound(0))
Console.Write("|");
}
Console.WriteLine();
}
// Fermeture reader
reader.Close();
// Fermeture base
connection.Close();
ma_form_Add_informations.ShowDialog();
}
else
{
MessageBox.Show("You must fill the name of project", " Reconfigure", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}
mais ca marche pas ca bug,
merci de votre aide