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 30 31 32 33 34 35 36 37 38 39 40 41 42
|
try
{
string lib = txtlib.Text;
DbConnection oConn;
DbDataAdapter oDA;
DbProviderFactory dpf = DbProviderFactories.GetFactory("System.Data.SqlServerCe.3.5");
oConn = dpf.CreateConnection();
oConn.ConnectionString = "Data Source = lovimag.sdf;Pwd=lov2010 ";
oDA = dpf.CreateDataAdapter();
oDA.SelectCommand = oConn.CreateCommand();
oDA.SelectCommand.CommandText = "select idcouleur,libcouleur from couleur";
DataSet oDS = new DataSet();
oDA.Fill(oDS, "couleur");
DataRow dr = oDS.Tables["couleur"].NewRow();
dr["libcouleur"]=lib.ToString();
oDS.Tables["couleur"].Rows.Add(dr);
oDA.InsertCommand = oConn.CreateCommand();
oDA.InsertCommand.CommandText = "insert into couleur (LIBCOULEUR) values(@libcouleur)";
DbParameter paraLIB = oDA.InsertCommand.CreateParameter();
paraLIB.SourceColumn = "libcouleur";
paraLIB.ParameterName = "libcouleur";
oDA.InsertCommand.Parameters.Add(paraLIB);
int n = oDA.Update(oDS.Tables["couleur"]);
if (n == 1)
MessageBox.Show("L'ajout s'est bien deroulé", "AJOUT D'UNE COULEUR", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "AJOUT D'UNE COULEUR", MessageBoxButtons.OK, MessageBoxIcon.Error);
} |
Partager