B
Boblemar
Hi all,
I've been struggeling for days on the following problem :
- I Have a table into SQL Server with an identity column (Auto increment)
- I created a strongly typed dataset using this table (Dataset is named
_DSTest and the datatable is called Test)
I want to populate the table and get back the identity values.
Here is my code :
Using ta As New _DSTestTableAdapters.TestTableAdapter
ta.Fill(ds.Test)
ds.Test.AddTestRow(ds.Test.NewTestRow())
Dim dtChanges As DataTable = ds.Test.GetChanges()
If dtChanges IsNot Nothing Then
Dim dt As _DSTest.TestDataTable = CType(dtChanges,
_DSTest.TestDataTable)
ta.Update(dt)
ds.Merge(dt)
ds.AcceptChanges()
Console.WriteLine(ds.Test.Rows(ds.Test.Count - 2))
Console.WriteLine(ds.Test.Rows(ds.Test.Count - 1))
End If
End Using
The problem is after merging the initial dataset, I have 2 rows in the
datatable :
- one with the value created by the database
- the other one with -1 (AutoIncrementSeed=-1 in my typed dataset).
I believe the problem is that when merging, the system doesn't see the 2
rows are the same...
How Can I solve the issue to have only One Row ?
I found 2 ways to do this :
- putting ds.RedjectChanges() before updating
- Or just don't deal with GetChanges, just update ds : ta.Update(ds)
But I believe there's a better way to do this. Can someone help me ?
Thanks
Bob
I've been struggeling for days on the following problem :
- I Have a table into SQL Server with an identity column (Auto increment)
- I created a strongly typed dataset using this table (Dataset is named
_DSTest and the datatable is called Test)
I want to populate the table and get back the identity values.
Here is my code :
Using ta As New _DSTestTableAdapters.TestTableAdapter
ta.Fill(ds.Test)
ds.Test.AddTestRow(ds.Test.NewTestRow())
Dim dtChanges As DataTable = ds.Test.GetChanges()
If dtChanges IsNot Nothing Then
Dim dt As _DSTest.TestDataTable = CType(dtChanges,
_DSTest.TestDataTable)
ta.Update(dt)
ds.Merge(dt)
ds.AcceptChanges()
Console.WriteLine(ds.Test.Rows(ds.Test.Count - 2))
Console.WriteLine(ds.Test.Rows(ds.Test.Count - 1))
End If
End Using
The problem is after merging the initial dataset, I have 2 rows in the
datatable :
- one with the value created by the database
- the other one with -1 (AutoIncrementSeed=-1 in my typed dataset).
I believe the problem is that when merging, the system doesn't see the 2
rows are the same...
How Can I solve the issue to have only One Row ?
I found 2 ways to do this :
- putting ds.RedjectChanges() before updating
- Or just don't deal with GetChanges, just update ds : ta.Update(ds)
But I believe there's a better way to do this. Can someone help me ?
Thanks
Bob