Results 1 to 5 of 5

Thread: Datagrid won't Refresh on Windows Form (RESOLVED)

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Location
    St Louis
    Posts
    6

    Unhappy Datagrid won't Refresh on Windows Form (RESOLVED)

    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.

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Once you delete the data from the db and from the grid, set the datagrid datasource again.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Location
    St Louis
    Posts
    6
    I'm fairly new to VB.NET so this may sound stupid.

    How do I delete the data from the grid?

  4. #4
    First you need to delete the information from your recordset
    Dim intID as integer
    intID=DataGrid1.text

    'Will work as long as the ID number is the first column. If not then use

    intID=DataGrid1.Columns(ID)

    "DELETE * FROM TableName WHERE IDField="& intID,Your Connection, 1, 2

    Then you Refresh the DataGrid

    Set DataGrid1.DataSource=your recordset
    DataGrid1.refresh

    Hope this helps

    Email Me if you have any questions
    [email protected]

  5. #5
    Lively Member
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    125
    hi compmanu!

    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!
    Attached Files Attached Files
    Last edited by siomai; Jul 22nd, 2004 at 08:51 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width