Bonjour,
Désolé si je ne suis pas dans le bon forum mais je ne savais pas trop où aller.
J'aimerai importer un DataRow dans une DataTable de la manière suivante :
Le souci est que le status du DataRow test est toujours à 'Detached' donc jamais ajouter dans ma DataTable, et j'aiemrai savoir pourquoi il n'est pas ajouter. Je sais qu'avec un NewRow cela fonctionne.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 DataTable cars = new DataTable("Cars"); DataColumn vin = new DataColumn("Vin"); vin.DataType = typeof(string); vin.MaxLength = 23; vin.Unique = true; vin.AllowDBNull = false; vin.Caption = "VIN"; cars.Columns.Add(vin); //Add the DataColums using defaults DataColumn make = new DataColumn("Make"); make.MaxLength = 35; make.AllowDBNull = false; cars.Columns.Add(make); DataColumn year = new DataColumn("Year", typeof(int)); year.AllowDBNull = false; cars.Columns.Add(year); //Derived column using expression DataColumn yearMake = new DataColumn("Year and Make"); yearMake.DataType = typeof(string); yearMake.MaxLength = 70; yearMake.Expression = "Year + ' ' + Make"; cars.Columns.Add(yearMake); //Set the Primary Key cars.PrimaryKey = new DataColumn[] { vin }; DataRow test = cars.NewRow(); test["Vin"] = "132649587ABCD"; test["Make"] = "Opel"; test["Year"] = 2012; cars.ImportRow(test);
D'avance merci pour votre aide
Partager