Bonjour,
Newbie en C#, je n'arrive pas à faire les modifications dans mon DataRow !
Quelqu'un a t-il la réponse ?
Ci-dessous mon code !
==============
static
void myProc()
{
SqlConnection connCible =
new
SqlConnection();
connCible.ConnectionString =
"Data Source=" +
"TEST" +
";Initial Catalog=" +
"myDB" +
";User id=titi;password=toto";
try
{
{
connCible.Open();
}
}
catch (
SqlException sqlEx)
{
Console.WriteLine(
"pas bon : " + sqlEx.Message,
"Error");
}
finally
{
//MessageBox.Show("it's ok pour la CIBLE !");
}
string cmdString;cmdString =
"Select * from " +
"TEST" +
"." +
"myDB" +
".dbo." +
"myTable";
SqlDataAdapter da =
new
SqlDataAdapter(cmdString, connCible);
DataTable tbl =
new
DataTable(
"myTable");
da.Fill(tbl);
string newCode;
string newType;
string newAssi;
foreach (
DataRow row
in tbl.Rows)
{
newCode = row[
"myCod"].ToString();
newType = row[
"myTyp"].ToString();
newAssi = row[
"myAss"].ToString();newCode = newCode.Substring(0,2) + newType + newAssi.Substring(1,2);
Console.WriteLine(
"\t" + row[
"myCod"] +
"\t" + row[
"myTyp"] +
"\t" + row[
"myAss"] +
"\t" + newCode);
// ET C'EST LA QUE CA NE MARCHE PAS, LES MAJ NE SONT PAS FAITES
row.BeginEdit();
row[
"myCod"] = newCode;
row.EndEdit();
row.AcceptChanges();
// POURQUOI ????
}
Console.ReadKey();
connCible.Close();
}