?
Solved

clear datatable

Posted on 2007-08-07
8
Medium Priority
?
1,981 Views
Last Modified: 2013-11-05
Hi,

i have the following code: -

            lstRigs.Items.Clear()
            sql = "SELECT * FROM Where_Used where ProductID ='" & cmbProducts.SelectedValue.ToString & "'"

            dbOpen()
            Dim da4 As New SqlClient.SqlDataAdapter(sql, oConn)
            da4.Fill(ds, "Where_Used") ' populate data set "da" with the data returned from sql command "ds" and set dataset name to "Rigs"


            lstRigs.DisplayMember = "RigID"
            lstRigs.ValueMember = "DeptID"
            lstRigs.DataSource = ds.Tables("Where_Used")

It wont allow me to clear the listbox I presume because its bound to a datatable. I'm trying to find out how I clear it please.

Many thanks
Lee
0
Comment
Question by:ljhodgett
  • 3
  • 3
  • 2
8 Comments
 
LVL 39

Expert Comment

by:appari
ID: 19645172
try

lstRigs.DataSource = nothing
0
 
LVL 18

Expert Comment

by:Ajay Sharma
ID: 19645227
appari is correct

first remove the datasource of control,
second clear the items
third again bind the data to the control


0
 

Author Comment

by:ljhodgett
ID: 19645247
Hi,

No joy i'm afraid. I've tried : -

            sql = "SELECT * FROM Where_Used where ProductID ='" & cmbProducts.SelectedValue.ToString & "'"

            lstRigs.DataSource = Nothing
            lstRigs.Items.Clear()
            lstRigs.Refresh()
            dbOpen()
            Dim da4 As New SqlClient.SqlDataAdapter(sql, oConn)
            da4.Fill(ds, "Where_Used") ' populate data set "da" with the data returned from sql command "ds" and set dataset name to "Rigs"
            'DataGridView1.DataSource = ds.Tables("Rigs")

            lstRigs.DisplayMember = "RigID"
            lstRigs.ValueMember = "DeptID"
            lstRigs.DataSource = ds.Tables("Where_Used")

but it still does not clear the datatable.

Best Regards
Lee
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 39

Expert Comment

by:appari
ID: 19645275
>>but it still does not clear the datatable.
what do you mean?
after clearing you are binding the new table again. so you are seeing the new results.
0
 
LVL 18

Expert Comment

by:Ajay Sharma
ID: 19645284
try clearing the dataset also

by

ds.clear
0
 

Author Comment

by:ljhodgett
ID: 19645349
Hi,

I'm not seeing the new results just adding to the end I presume because the datatable is not empty. I did think of clearing the dataset using ds.clear but the problem is that I use the same dataset fro multiple datatables. Is there anyway I can clear datatable da4 by itself.

Many thanks
Lee
0
 
LVL 18

Accepted Solution

by:
Ajay Sharma earned 2000 total points
ID: 19645365
ds.Tables(0).Clear

pass the table number or name as the parameter
0
 

Author Comment

by:ljhodgett
ID: 19645413
I've tried: -

            ds.Tables("da4").Clear()
            dbOpen()
            Dim da4 As New SqlClient.SqlDataAdapter(sql, oConn)
            da4.Fill(ds, "Where_Used") ' populate data set "da" with the data returned from sql command "ds" and set dataset name to "Rigs"
            'DataGridView1.DataSource = ds.Tables("Rigs")

            lstRigs.DisplayMember = "RigID"
            lstRigs.ValueMember = "DeptID"
            lstRigs.DataSource = ds.Tables("Where_Used")

but it comes up Object reference not set to an instance of an object.

Best Regards
Lee
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 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