Results 1 to 7 of 7

Thread: How to Clear the DataGrid...?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    7

    Question How to Clear the DataGrid...?

    Dear Friends,

    I have a project for Sales, and every time I have to clear the DataGrid when I Post the Transaction sales or Cancel it.

    I'm trying to do this code to delete the table but doesn't work till now coz I have to make refresh to the record set and I don't know how?
    anyway this is the code

    PHP Code:
    If rs.RecordCount 0 Then
         rs
    .MoveFirst
             
    For aloop 0 To rs.RecordCount 1
          Cn
    .Execute ("delete * from TmpDetails")
          
    rs.MoveFirst
                     DataGrid1
    .Refresh 

    So I hope if there is anyone can help me and if there is any Questions plz let me know

    note that I'm not using any Data Control (ADO) to connect I programmed it by code only

    and thx alot

    Best Regards

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to Clear the DataGrid...?

    I'm a little confused by what you are after.

    Are you trying to delete all records in a database table called tmpDetails, clear a datagrid, or both?

    To delete all records in a table you do not have to loop.
    vb Code:
    1. 'this is all that is required
    2.  Cn.Execute "delete from TmpDetails"

  3. #3
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: How to Clear the DataGrid...?

    I'm trying to do this code to delete the table
    I believe you are trying to delete records in TmpDetails.
    since you are using action query loop is not required
    vb Code:
    1. Private Sub Command1_Click()
    2. If rs.RecordCount > 0 Then
    3.     Cn.Execute ("DELETE FROM TmpDetails")
    4.     datagrid1.Refresh
    5. End If
    6. End Sub

  4. #4
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: How to Clear the DataGrid...?

    If you really want to delete a TABLE
    vb Code:
    1. cn.Execute("DELETE TABLE TmpDetails")

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    7

    Re: How to Clear the DataGrid...?

    dear friends,,
    thx for the repaly,, I'm using 2 tables one is temporary and one for storing the data in.
    so when I POST the Transaction I have to copy all the data from the TmpDetails table to the TrxDetails table, then delete the TmpDetails.
    now it's work the problem only is the DataGrid still have the data on it, i wanna it to clear it.
    this is the full code for the Cancel button

    vb Code:
    1. X = MsgBox("Are you Sure to Cancel this Transaction?" & Chr(10), vbYesNo + vbQuestion, "CANCEL")
    2.       If X <> vbYes Then Exit Sub
    3.   cmdCancel.Enabled = False
    4.   CmdClose.Enabled = True
    5. ' This code to Transfer the data from TmpDetail table into TrxDetail table
    6.     Set rs = New ADODB.Recordset    
    7.       If rs.State = adStateOpen Then rs.Close      
    8.  rs.Open "select * from TmpDetails", Cn, adOpenStatic, adLockReadOnly
    9.  If rs.RecordCount > 0 Then
    10.      rs.MoveFirst
    11.          For aloop = 0 To rs.RecordCount - 1
    12.  Csql1 = ""
    13.  Csql1 = "Insert Into TrxDetails(SalesType, SpecialOrder, BARCODE, UOMCode, Qty, StdUnitPrice, SalesUnitPrice)" & _
    14.  "VALUES('" & rs("SalesType") & "','" & rs("SpecialOrder") & "','" & rs("Barcode") & _
    15.  "','" & rs("UOMCode") & "','" & rs("Qty") & "','" & rs("StdUnitPrice") & "','" & rs("SalesUnitPrice") & "')"
    16.          
    17.          Cn.Execute Csql1      
    18.              rs.MoveNext
    19.  Next
    20.      If rs.RecordCount > 0 Then
    21.      rs.MoveFirst
    22.          For aloop = 0 To rs.RecordCount - 1
    23.       Cn.Execute ("delete * from TmpDetails")    
    24.       rs.MoveFirst
    25.              DataGrid1.Refresh
    26.              FRMSALES.Refresh
    27.  Next
    28.  End If
    29.   End If

    I hope u will understand me.

    Note: in MS flex Grid for example when I need to clear everything only I have to write this code

    vb Code:
    1. MSFlexGrid1.Clear

    thx again 4 all
    Best Regards

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    7

    Re: How to Clear the DataGrid...?

    waiting for ur Suggestions my friends ...

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: How to Clear the DataGrid...?

    Don't use a bound control, use MSFlexGrid.

    Or reset rs
    Code:
    If rs.RecordCount > 0 Then
      Cn.Execute ("delete * from TmpDetails")
      Set rs = Nothing 'to reclaim the memory it used
      Set rs = New ADODB.Recordset 'it's empty now - no records
      DataGrid1.Refresh 'if rs is its datasource, it now has a blank datasource
      FRMSALES.Refresh 'I don't know why you have this
    End If
    (You don't have to walk through the recordset to clear the table. Delete * deletes all records.)
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

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