Link to home
Start Free TrialLog in
Avatar of b001
b001Flag for Afghanistan

asked on

clear data in a dataset table

Hi Experts
I have dataset  DS filled with  data form 2 tables tablename1,tablenameRef
            Fmsadapter.Fill(dS, tableName)
            REFadapter.Fill(dS, tableNameRef)
I would like to clear data of only one table called  tablenameRef everytime I Keydown a textbox.

The following command clear all the data.
dS.Tables.Clear()
Please help
Thanks
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

You need to call Clear() on the datatable itself, rather than the dataset:
dS.Tables(tableNameRef).Clear()

Open in new window

Hi  b001;

The sample code will clear the Table tablenameRef of its data every time a key is pressed while TextBox1 has focus.

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

        ds.Tables("tablenameRef").Clear()

    End Sub

Open in new window


Fernando
@ carl_tawn;

You need quotes around the table name.
tableNameRef in the original posted is unqouted, which would suggest it is a variable rather than the name of the table itself, hence no quotes.
Avatar of b001

ASKER

tableNameRef is veraible.
I tried the following codes and I have error


            dS.Tables(tableNameRef).Clear()
            dS.Tables("tableNameRef").Clear()
            dS.Tables(" & tableNameRef & ").Clear()

eror:
Object reference not set to an instance of an object.
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi b001;

You can use a numeric index. For example if tableNameRef was loaded into the DataSet object as the second table then the code in the snippet will work. If it was the first table loaded then change (1) to (0) in the code snippet.

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

        ds.Tables(1).Clear()

    End Sub

Open in new window