Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

clear data in a dataset table

Posted on 2011-02-25
7
Medium Priority
?
593 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

609 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