Short delay in cmd.ExecuteScalar

J Trahair

Well-known member
Joined
May 14, 2008
Messages
175
Location
Spain
Programming Experience
10+
Hi. I have an unbound datagridview showing 6 or 7 user names and details.
I have a delete button for deleting a user record, followed by the procedures which re-display the data without the deleted user.

VB.NET:
objConn = New OleDb.OleDbConnection(mstrOLEConnectionString)
objConn.Open()
Dim cmd As New System.Data.OleDb.OleDbCommand("", objConn)
cmd.CommandTimeout = 60
cmd.Connection = objConn
cmd.CommandType = CommandType.Text
cmd.CommandText = "DELETE FROM Users WHERE UserName = '" & grd1.Item(1, grd1.CurrentCellAddress.Y).Value.ToString & "'"
'cmd.ExecuteScalar()
cmd.ExecuteNonQuery()

Call SetUpGrd1()   'clears the existing data from dgv
Call FillGrd1()        're-populates dgv from database
The problem is, it happens so fast that the re-displayed data still includes the deleted user. When I run the SetUpGrd1()/FillGrd1() procedures by themselves again, the deleted user has gone.
Is there a 'hurry up and write this data' routine which I can insert before the Call SetUpGrd1()? Thank you.

I should add, I've tried cmd.ExecuteScalar() and cmd.ExecuteNonQuery(), with the same effect. Hence one being commented out.
 
if you do your data access the way microsoft proscribe (see the dw2 link in my signature, start with Creating a Simple Data App) then you wont see this behaviour, because you have your data in a table locally, you mark it was deleted, you call tableadapter.update, the tableadapter issues a delete query, then accepts the changes to the local grid, the data disappears locally and from the db..

the important part is that no re-fill operation is needed; the sync with the database, by its very nature ensures that what you see is what is in the db
 
Back
Top