Retrieve the PK after an add into an in memory DataTable
-
I know how to do this in SQL but I must do it from C#. The DataTable is actually in memory (an xsd). So I have some DataSet called "Converted" and in it is a Table called "Results" which has a relationship with another table called "Descriptions". I am converting some data (thus the name) to an in memory table I have created. The problem is that I need the Primary Key of the "Results" last insert in order to populate the "Descriptions". How can I get the last inserted primary key? The bellow code shows what I am doing. In the section Descriptions is where various paramaters from the raw data are then combined into multiple entries into the Descriptions table. I ofcourse need to link them back to the current row I am processing.
foreach (RawData.ResultsRow rRow in \_rawData.Results) { Converted.ResultsRow nRow = MemDataSet.Results.NewResultsRow(); nRow.Param = rRow.SomeParam MemDataSet.Results.AddResultsRow(nRow); //int pk = ?????? ... #region Descriptions ConvertedDescriptionsRow dRow = MemDataSet.Descriptions.NewDescriptionsRow(); dRow.Param = rRow.SomeDescriptor dRow.ResultsFK = pk; MemDataSet.Descriptions.AddDescriptionsRow(dRow); #endregion Descriptions }
"9 Pregnent woman can not have a baby in 1 month" -Uknown
-
I know how to do this in SQL but I must do it from C#. The DataTable is actually in memory (an xsd). So I have some DataSet called "Converted" and in it is a Table called "Results" which has a relationship with another table called "Descriptions". I am converting some data (thus the name) to an in memory table I have created. The problem is that I need the Primary Key of the "Results" last insert in order to populate the "Descriptions". How can I get the last inserted primary key? The bellow code shows what I am doing. In the section Descriptions is where various paramaters from the raw data are then combined into multiple entries into the Descriptions table. I ofcourse need to link them back to the current row I am processing.
foreach (RawData.ResultsRow rRow in \_rawData.Results) { Converted.ResultsRow nRow = MemDataSet.Results.NewResultsRow(); nRow.Param = rRow.SomeParam MemDataSet.Results.AddResultsRow(nRow); //int pk = ?????? ... #region Descriptions ConvertedDescriptionsRow dRow = MemDataSet.Descriptions.NewDescriptionsRow(); dRow.Param = rRow.SomeDescriptor dRow.ResultsFK = pk; MemDataSet.Descriptions.AddDescriptionsRow(dRow); #endregion Descriptions }
"9 Pregnent woman can not have a baby in 1 month" -Uknown
I'm not going to give you the answer but only because you put regions inside of methods.
Need custom software developed? I do C# development and consulting all over the United States. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
-
I'm not going to give you the answer but only because you put regions inside of methods.
Need custom software developed? I do C# development and consulting all over the United States. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
What sort of answer is that, he can have regions inside a method (NOT), how about nested regions and regions from the middle of one method to the middle of another method. I must admit I have never seen regions used inside a method
Never underestimate the power of human stupidity RAH
-
I know how to do this in SQL but I must do it from C#. The DataTable is actually in memory (an xsd). So I have some DataSet called "Converted" and in it is a Table called "Results" which has a relationship with another table called "Descriptions". I am converting some data (thus the name) to an in memory table I have created. The problem is that I need the Primary Key of the "Results" last insert in order to populate the "Descriptions". How can I get the last inserted primary key? The bellow code shows what I am doing. In the section Descriptions is where various paramaters from the raw data are then combined into multiple entries into the Descriptions table. I ofcourse need to link them back to the current row I am processing.
foreach (RawData.ResultsRow rRow in \_rawData.Results) { Converted.ResultsRow nRow = MemDataSet.Results.NewResultsRow(); nRow.Param = rRow.SomeParam MemDataSet.Results.AddResultsRow(nRow); //int pk = ?????? ... #region Descriptions ConvertedDescriptionsRow dRow = MemDataSet.Descriptions.NewDescriptionsRow(); dRow.Param = rRow.SomeDescriptor dRow.ResultsFK = pk; MemDataSet.Descriptions.AddDescriptionsRow(dRow); #endregion Descriptions }
"9 Pregnent woman can not have a baby in 1 month" -Uknown