Solved

clear data in a dataset table

Posted on 2011-02-25
7
584 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 62

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 62

Expert Comment

by:Fernando Soto
ID: 34983314
@ carl_tawn;

You need quotes around the table name.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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 500 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 62

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Separate a number and letter from a string 25 24
Setting location of a form 4 22
Get String split 5 31
Different Delete Messages 7 10
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now