[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

clear data in a dataset table

Posted on 2011-02-25
7
Medium Priority
?
597 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:b001
  • 3
  • 3
7 Comments
 
LVL 52

Expert Comment

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

Open in new window

0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 34983290
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
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 34983314
@ carl_tawn;

You need quotes around the table name.
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34983604
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.
0
 

Author Comment

by:b001
ID: 34986807
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.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 34986894
That would suggest that there isn't a table in your dataset with that name then. Use the following to check for the tables existence before trying to clear it:
If dS.Tables.Contains(tableNameRef) Then
    dS.Tables(tableNameRef).Clear()
End If

Open in new window

0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 34987008
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

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question