Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strongly typed dataset issue

Status
Not open for further replies.

Kenny62

Programmer
Mar 3, 2004
54
GB
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top