?
Solved

clear data in a dataset table

Posted on 2011-02-25
7
Medium Priority
?
591 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 63

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 63

Expert Comment

by:Fernando Soto
ID: 34983314
@ carl_tawn;

You need quotes around the table name.
0
Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

 
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 63

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

752 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