I am having problems refreshing my datagrid on a windows form. I have a master/detail form relationship on the form and I am deleting the data from a SQL Servre database. The data gets deleted with no problem but I cannot get the grid to refresh and show the data gone without closing the form and reopening it.
Here is the code I use to load the data initially:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DsHeaderDetail1.Clear()
SqlDataAdapter1.Fill(DsHeaderDetail1)
SqlDataAdapter2.Fill(DsHeaderDetail1)
End Sub
Here is the code I use to delete the data from the SQL database:
Public Sub DeletePromoOrder(ByVal ID As Integer)
On Error GoTo ue_error
Dim CMD As String
Dim myConn As SqlConnection = New SqlConnection("Data Source=STL6;Integrated Security=SSPI;Initial Catalog=RWNPROD")
' ------------ DELETE DETAIL RECORDS -----------------
CMD = "DELETE FROM PODetail WHERE PODID = " & ID & ""
'Dim DeleteDtlSQL As String =
Dim DeleteDtlCMD As New SqlCommand(CMD, myConn)
'SqlDataAdapter1.SelectCommand = DeleteDtlCMD
myConn.Open()
DeleteDtlCMD.ExecuteNonQuery()
' ------------ DELETE HEADER RECORDS -----------------
Dim DeleteHdrSQL As String = "DELETE FROM POHeader WHERE POHID = " & ID & ""
Dim DeleteHdrCMD As SqlCommand = New SqlCommand(DeleteHdrSQL, myConn)
SqlDataAdapter1.SelectCommand = DeleteHdrCMD
DeleteHdrCMD.ExecuteNonQuery()
myConn.Close()
' I need help here to know how to refresh the datagrid(s). They are named DataGrid1(Master) and Datagrid2(Detail)
Exit Sub
ue_error:
Call UE("Item Add: ")
Resume Next
End Sub
Please help!!!!!!!!!!!!!
Last edited by ronniedfw; Jul 28th, 2003 at 03:32 PM.
I'm also new in programming and vb.net... just want to ask if this also works with a windows form with only one datagrid for the details and textboxes for the header? If so, how will i make my delete button work? Can I also ask you with updating/editing records? Please help me cause I'm really having a hard time with my program. i will attach my program and I hope you'd take a look at it. Many thanks!
Btw, my datagrid is not bound in the form load just yet to make it a flexgrid (allow input from users). I just want to clear its contents for a another transaction (just in case the user wants to input another transaction).
Please please help me! I need it so badly!
Last edited by siomai; Jul 22nd, 2004 at 08:51 PM.