ljhodgett
asked on
clear datatable
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(s ql, 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
i have the following code: -
lstRigs.Items.Clear()
sql = "SELECT * FROM Where_Used where ProductID ='" & cmbProducts.SelectedValue.
dbOpen()
Dim da4 As New SqlClient.SqlDataAdapter(s
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
appari is correct
first remove the datasource of control,
second clear the items
third again bind the data to the control
first remove the datasource of control,
second clear the items
third again bind the data to the control
ASKER
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(s ql, 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
No joy i'm afraid. I've tried : -
sql = "SELECT * FROM Where_Used where ProductID ='" & cmbProducts.SelectedValue.
lstRigs.DataSource = Nothing
lstRigs.Items.Clear()
lstRigs.Refresh()
dbOpen()
Dim da4 As New SqlClient.SqlDataAdapter(s
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
>>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.
what do you mean?
after clearing you are binding the new table again. so you are seeing the new results.
try clearing the dataset also
by
ds.clear
by
ds.clear
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've tried: -
ds.Tables("da4").Clear()
dbOpen()
Dim da4 As New SqlClient.SqlDataAdapter(s ql, 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
ds.Tables("da4").Clear()
dbOpen()
Dim da4 As New SqlClient.SqlDataAdapter(s
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
lstRigs.DataSource = nothing