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
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:
'this is all that is required
Cn.Execute "delete from TmpDetails"
Re: How to Clear the DataGrid...?
Quote:
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:
Private Sub Command1_Click()
If rs.RecordCount > 0 Then
Cn.Execute ("DELETE FROM TmpDetails")
datagrid1.Refresh
End If
End Sub
Re: How to Clear the DataGrid...?
If you really want to delete a TABLE
vb Code:
cn.Execute("DELETE TABLE TmpDetails")
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:
X = MsgBox("Are you Sure to Cancel this Transaction?" & Chr(10), vbYesNo + vbQuestion, "CANCEL")
If X <> vbYes Then Exit Sub
cmdCancel.Enabled = False
CmdClose.Enabled = True
' This code to Transfer the data from TmpDetail table into TrxDetail table
Set rs = New ADODB.Recordset
If rs.State = adStateOpen Then rs.Close
rs.Open "select * from TmpDetails", Cn, adOpenStatic, adLockReadOnly
If rs.RecordCount > 0 Then
rs.MoveFirst
For aloop = 0 To rs.RecordCount - 1
Csql1 = ""
Csql1 = "Insert Into TrxDetails(SalesType, SpecialOrder, BARCODE, UOMCode, Qty, StdUnitPrice, SalesUnitPrice)" & _
"VALUES('" & rs("SalesType") & "','" & rs("SpecialOrder") & "','" & rs("Barcode") & _
"','" & rs("UOMCode") & "','" & rs("Qty") & "','" & rs("StdUnitPrice") & "','" & rs("SalesUnitPrice") & "')"
Cn.Execute Csql1
rs.MoveNext
Next
If rs.RecordCount > 0 Then
rs.MoveFirst
For aloop = 0 To rs.RecordCount - 1
Cn.Execute ("delete * from TmpDetails")
rs.MoveFirst
DataGrid1.Refresh
FRMSALES.Refresh
Next
End If
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
thx again 4 all
Best Regards
Re: How to Clear the DataGrid...?
waiting for ur Suggestions my friends ...
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.)