problem with query

danijel.drmic

Member
Joined
Jul 2, 2009
Messages
10
Programming Experience
5-10
when I am writing something in a textbox called SIF and click button6 in datagridview1 get a letter by letter. each letter in the new row. then change text in the SIF and again click on button6. old base deleting and review the new (as I conceived). However, when I click on query2 that I made in the datagridview task -> add query. I get the old and new data. I want only new data. please help:(
VB.NET:
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Frek1DataSet.Clear()
        Me.SlovoBindingSource.AddNew()
        For i = 0 To SIF.TextLength - 1
            TextBox1.Text = SIF.Text.Chars(i)
            Me.SlovoBindingSource.AddNew()
        Next
        SlovoTableAdapter.Update(Frek1DataSet)
    End Sub

    Private Sub Query2ToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Query2ToolStripButton.Click
        Try
            Me.SlovoTableAdapter.query2(Me.Frek1DataSet.slovo)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try

    End Sub
 
Please post in the most appropriate forum for the topic. Thread moved from Windows Forms.

You are populating a DataTable that already contains data, so you end up with the old data and the new. You need to clear out the old data first. You can do that implicitly, by setting the ClearBeforeFill property of your TableAdapter to True, or explicitly, by calling the Clear method of your DataTable.
 
if I click on button6 that says
VB.NET:
Frek1DataSet.Clear ()
SlovoTableAdapter.Update(Frek1DataSet)
After that, if I click on query2 that says
VB.NET:
Me.SlovoTableAdapter.query2(Me.Frek1DataSet.slovo)
I still get results that have been deleted. what I do wrong? SlovoTableAdapter still remembers the old data from the database
 
You're supposed to Clear the DataTable before you Fill it, not before you Update it. If you Clear it before you Update it then you're wiping out all your changes before saving them.
 

Latest posts

Back
Top