Hi - i'm using a strongly typed dataset called say, CategoryDS - which links to a table Category in a DB. Category table has the following field:
CategoryID , int, (key)
CategoryName, string
Description, string
VB.Net has created all the methods and properties for CategoryDS - great.
I'm have problems when it comes to adding a new record to the DS. The DS CategoryID field is out of sync with the last value written to the DB. So - i've tried writing the @@IDENTITY value back to the CategoryID field (having set properties Autoincrement = FALSE, ReadOnly = FALSE)
The DS CategoryID does'nt change value - why. Where have i gone wrong. Am i using the typed Dataset incorrectly. If so please explain.
If Not IsNothing(NewDR) Then
Dim sSQL As String
Dim Cmd As OleDbCommand
'Do re-query...only require ID
sSQL = "SELECT DISTINCT @@IDENTITY FROM Categories"
Cmd = New OleDbCommand(sSQL, g_DBConnect, ThisTransaction)
'New ID after add record to DB
m_NewID = CInt(Cmd.ExecuteScalar())
NewDR.CategoryID = m_NewID
Debug.WriteLine("CID:" & CStr(NewDR.CategoryID))
NewDR.AcceptChanges()
End If
Thanks for you help in advance
CategoryID , int, (key)
CategoryName, string
Description, string
VB.Net has created all the methods and properties for CategoryDS - great.
I'm have problems when it comes to adding a new record to the DS. The DS CategoryID field is out of sync with the last value written to the DB. So - i've tried writing the @@IDENTITY value back to the CategoryID field (having set properties Autoincrement = FALSE, ReadOnly = FALSE)
The DS CategoryID does'nt change value - why. Where have i gone wrong. Am i using the typed Dataset incorrectly. If so please explain.
If Not IsNothing(NewDR) Then
Dim sSQL As String
Dim Cmd As OleDbCommand
'Do re-query...only require ID
sSQL = "SELECT DISTINCT @@IDENTITY FROM Categories"
Cmd = New OleDbCommand(sSQL, g_DBConnect, ThisTransaction)
'New ID after add record to DB
m_NewID = CInt(Cmd.ExecuteScalar())
NewDR.CategoryID = m_NewID
Debug.WriteLine("CID:" & CStr(NewDR.CategoryID))
NewDR.AcceptChanges()
End If
Thanks for you help in advance