G
gsb58
Hi!
A mainform is being used to show records from a table in an sql
database.
A button on the main form will load a new form that allows the user to
add, delete, update and search certain records in the underlying table
of the main form.
My question:
If the user add's a record:
How can I refresh the underlying table of the main form from the second
form and show the changes in the datagrid on the mainform?
Here's the code in the 'Update-event' of the second form:
Dim intPosition As Integer
Dim objCommand As SqlCommand = New SqlCommand
intPosition = myCurrencyManager.Position
objCommand.Connection = myConnection
objCommand.CommandText = "UPDATE titles " & _
"SET title = @title,price = @price WHERE title_id = @title_id"
objCommand.CommandType = CommandType.Text
objCommand.Parameters.Add("@title", txtBookTitle.Text)
objCommand.Parameters.Add("@price", txtPrice.Text).DbType =
DbType.Currency
objCommand.Parameters.Add("@title_id",
BindingContext(myDV).Current("title_id"))
Try
myConnection.Open()
objCommand.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message,
"btnUpdate_EXECUTENONQUERY_ERROR", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
myConnection.Close()
FillDataSetAndView()
BindFields()
End Try
myCurrencyManager.Position = intPosition
ShowPosition()
StatusBar1.Text = "Record updated"
'Here I will refresh the main form, I think...
'Me.Close()
P.S
This is a training case and the example is taken from VB.NET 2nd
Edition
Me.Name
A mainform is being used to show records from a table in an sql
database.
A button on the main form will load a new form that allows the user to
add, delete, update and search certain records in the underlying table
of the main form.
My question:
If the user add's a record:
How can I refresh the underlying table of the main form from the second
form and show the changes in the datagrid on the mainform?
Here's the code in the 'Update-event' of the second form:
Dim intPosition As Integer
Dim objCommand As SqlCommand = New SqlCommand
intPosition = myCurrencyManager.Position
objCommand.Connection = myConnection
objCommand.CommandText = "UPDATE titles " & _
"SET title = @title,price = @price WHERE title_id = @title_id"
objCommand.CommandType = CommandType.Text
objCommand.Parameters.Add("@title", txtBookTitle.Text)
objCommand.Parameters.Add("@price", txtPrice.Text).DbType =
DbType.Currency
objCommand.Parameters.Add("@title_id",
BindingContext(myDV).Current("title_id"))
Try
myConnection.Open()
objCommand.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message,
"btnUpdate_EXECUTENONQUERY_ERROR", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
myConnection.Close()
FillDataSetAndView()
BindFields()
End Try
myCurrencyManager.Position = intPosition
ShowPosition()
StatusBar1.Text = "Record updated"
'Here I will refresh the main form, I think...
'Me.Close()
P.S
This is a training case and the example is taken from VB.NET 2nd
Edition
Me.Name