|
-
Feb 3rd, 2004, 10:36 PM
#1
Thread Starter
Registered User
-
Feb 4th, 2004, 03:54 AM
#2
Sleep mode
Refresh method of DataGrid just grahically redraw the Grid . For such problem , either I refill the dataset or just recall the procdure that feeds the grid with data . This will get data from source and back them up in the DataGrid .
-
Feb 4th, 2004, 03:55 AM
#3
Thread Starter
Registered User
ok I found a solution but it wasn't straight forward This is for an access db btw >2000.
Anyway what you need to do is declare the dataadapter that fills the datagrid with events like so and create a command object too oh and you need the connection of course.
VB Code:
Dim WithEvents da2 As New System.Data.OleDb.OleDbDataAdapter()
Dim ObjConn As New Data.OleDb.OleDbConnection()
Dim cmdGetIdentity As Data.OleDb.OleDbCommand
ok now in the forms load event set the text of your command object like this:
VB Code:
cmdGetIdentity = New Data.OleDb.OleDbCommand("SELECT @@IDENTITY", ObjConn)
finally add this code to your dataadapters row updated event:
VB Code:
Private Sub da2_RowUpdated(ByVal sender As Object, ByVal e As System.Data.OleDb.OleDbRowUpdatedEventArgs) Handles da2.RowUpdated
If e.Status = UpdateStatus.Continue AndAlso e.StatementType = StatementType.Insert Then
' If this is an INSERT operation...
' Execute the post-update query to fetch new @@Identity
ObjConn.Open()
e.Row("HrsWrkId") = CInt(cmdGetIdentity.ExecuteScalar)' you need to put the name of your id field for the table for it to work for you i.e change HrsWrkId to the relevant name.
e.Row.AcceptChanges()
ObjConn.Close()
End If
End Sub
and that works for me.
here is the article I worked off, although I had to fiddle to get it working which is why I posted the answer. 
http://msdn.microsoft.com/library/de...anidcrisis.asp
-
Feb 4th, 2004, 04:02 AM
#4
Thread Starter
Registered User
Originally posted by Pirate
Refresh method of DataGrid just grahically redraw the Grid . For such problem , either I refill the dataset or just recall the procdure that feeds the grid with data . This will get data from source and back them up in the DataGrid .
Yeah i worked that out Pirate, the problem was that I had 2 linked tables being displayed in the grid and if the user didn't get the id back when they created a record in the main table then the user couldn't create records in the sub table, it also creates lots of traffic that can be avoided as well as navigation issues. Luckily it wasn't that hard after all
-
Feb 4th, 2004, 04:08 AM
#5
Sleep mode
Simply put , refilling the dataset and bind it back to the Grid is perfect I think . And for the solution you came up with , we'd discussed it here . You could have a look . http://www.vbforums.com/showthread.p...light=IDENTITY
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|