previous result does not go

suju_26pro

Well-known member
Joined
May 4, 2011
Messages
48
Programming Experience
Beginner
hello .. i hd a form , what i want is that the user will search the database either by entering Party Name or By date ..I hd succesfully acheived this , but the problem is that , when i search for partyname , the result are showned in datagrideview , but when u tried to search again the previous result does not go , its still present in datgridview..how do i get out of it ...
for much better understanding i hd posted image down there ..plz help me out

Private Sub Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Da = New OleDb.OleDbDataAdapter("Select * from demo where DateOfPurchase = '" + txtsdateofpurchase.Text + "'", Cnn)
Da.Fill(ds, "demo")
DataGridView1.DataSource = ds.Tables(0)
DataGridView1.Refresh()

End Sub
 

Attachments

  • untitled.jpg
    untitled.jpg
    161.8 KB · Views: 36
First of all, get rid of the Refresh call. It does nothing useful in this context.

As for the question, the problem is that you keep Filling the same DataTable over and over without ever removing the old data. The data doesn't remove itself. If you want to clear the data then call Clear on the DataTable.

Notice I keep saying DataTable and not DataSet. Your DataSet is useless because all it does is contain a single DataTable. Get rid of it and just use a DataTable.
 
Thnx alot ..its work!!
Now stuck in othere major problem , nt getting an idea to perform this calculate: Hope you help me out;
Actually me wrking on Inventory Management Application:
Is it possible to call one column from other table to perform subtraction,
i have one column which contain quantity rows , i want this quantity rows total to subtract from another table quantity row of another table to find out the remaining stock ,
(EG Total of 1 Quantity rows will calculated using following code:
Private Function Totalstock() As Double
Dim tot As Double = 0

Dim i As Integer = 0
For i = 0 To DataGridView2.Rows.Count - 1
tot = tot + Convert.ToDouble(DataGridView2.Rows(i).Cells("Quantity").Value)

Next i
Return tot
End Function

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If DataGridView2.Rows.Count > 0 Then
TextBox2.Text = Totalstock().ToString("c")
End If
End Sub
This will give me a sum of all amount , Same will be done for column of other table , this will also give me sum of all column..
So by subtracting this to amount , i will get the reaming stock number...
Me thinking of this logic , is this possible...If yes thn plz guide me out or else help me how do get the remaining stock detail...
thnx In Advance
 
Datagridview Issue

Hello ,

I had made a databse application , in one of my form , i had two search criteria , one search by partyname , which will fetch a data from demo table : the code is
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

ds.Clear()
Da = New OleDb.OleDbDataAdapter("Select * from demo where PartyName = '" + txtspartyname.Text + "'", Cnn)
Da.Fill(ds, "demo")
DataGridView1.DataSource = ds.Tables(0)


End Sub

the othere criteria is to search by customername , wgich will fetch the data from "sales" table : The Code

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
ds.Clear()
Da = New OleDb.OleDbDataAdapter("Select * from sales where CustomerName = '" + TextBox6.Text + "'", Cnn)
Da.Fill(ds, "sales")
DataGridView1.DataSource = ds.Tables(0)

End Sub

Both Button work fine,

The problem is that if i search by "partyname" , the result is display in grid view , but when i go to search by "customername" , the previous "demotable" is still there in datagridview , so my search criteria doesn't give me any result , same case if i go for search by "CustomerName" , the result are display but when i go to search by "Partyname " the prvious "Sales table " is still present . ..Hope u got wht me trying to . Plz Help me out...
 

Attachments

  • untitled.JPG
    untitled.JPG
    51.2 KB · Views: 28
Back
Top