每次执行它时,它都会使用新值复制数据并将其附加到DatagridView的先前内容中。我想清除内容然后添加新值..有人可以帮助我吗? 这是我的代码:
Private Sub lvTable_ItemChecked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles lvTable.ItemChecked
Try
If lvTable.CheckedItems.Count > 0 Then
Dim Condition As String = ""
Dim Condition1 As String = ""
For I = 0 To lvTable.CheckedItems.Count - 1
Condition += String.Format("'{0}',", lvTable.CheckedItems(I).Text)
Condition1 += String.Format("'{0}',", lvTable.CheckedItems(I).SubItems(1).Text)
Next
Condition = Condition.Substring(0, Condition.Length - 1)
Condition1 = Condition1.Substring(0, Condition1.Length - 1)
DataGridView2.Visible = True
con = New OleDbConnection(cs)
con.Open()
Dim OleDb As String = "Select Item_ID,DishName, SUM(Qty), KOTGenerationItems.Rate, SUM(Amount), DiscPer, SUM(Disc), VATPer, SUM(VATAmt), STPer, SUM(STAmt), SCPer, SUM(SCAmt), SUM(TotalAmt),TableNo,GroupName from KOTGeneration,KOTGenerationItems,Dish where KOTGeneration.TicketID=KOTGenerationItems.Ticket_ID and KOTGenerationItems.Item_ID=Dish.ItemID and TableNo in (" & Condition & ") and GroupName in (" & Condition1 & ") group by Item_ID,DishName,KOTGenerationItems.Rate,DiscPer,VATPer,STPer,SCPer,TableNo,GroupName order by TableNo"
cmd = New OleDbCommand(OleDb, con)
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
DataGridView2.Rows.Clear()
While (rdr.Read() = True)
DataGridView2.Rows.Add(rdr(0), rdr(1), rdr(2), rdr(3), rdr(4), rdr(5), rdr(6), rdr(7), rdr(8), rdr(9), rdr(10), rdr(11), rdr(12), rdr(13), rdr(14), rdr(15))
End While
con.Close()
txtCash.Text = "0.00"
TotalCalc1()
Calc()
Else
Clear()
DataGridView2.Rows.Clear()
DataGridView2.Visible = False
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub