Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I remove a table from a DataSet 1

Status
Not open for further replies.

RotorTorque

Programmer
Apr 29, 2007
100
US
Hi all,
I am using the following code in my VB.Net 2005 application to get data into a DataSet and then load a combobox:

Code:
Public Sub GetSubType(ByVal cbo As ComboBox, ByVal intX As Integer)
       Dim SQLConn As New SqlClient.SqlConnection
       SQLConn = New SqlClient.SqlConnection
       SQLConn.ConnectionString = My.Settings.HelpDeskConnectionString
       SQLConn.Open()


       'Declare a SQL DataAdapter object
       Dim objDataAdapter As New SqlDataAdapter()

       'Assign a new SQLCommand to the SelectCommand property
       objDataAdapter.SelectCommand = New SqlCommand

       'Set the SelectCommand properties...
        objDataAdapter.SelectCommand.Connection = SQLConn
        objDataAdapter.SelectCommand.CommandText = "SELECT CaseSubType FROM CaseSubType WHERE(CaseTypeID = '" & intX & "')" 


       objDataAdapter.Fill(objDataSet, "Sub Types")
       SQLConn.Close()
       cbo.DataSource = Nothing
       cbo.Items.Clear()
       cbo.DataSource = objDataSet.Tables("Sub Types")
       cbo.DisplayMember = "CaseSubType"

       'Clean Up
       objDataAdapter = Nothing
       SQLConn = Nothing
End Sub

The ComboBox needs to be refreshed constantly. I am already clearing the ComboBox and setting its DataSource to Nothing. But items keep getting added to the Combobox. I think I need to Drop the table from the DataSet first and then add it again. How can I remove the table from the DataSet?

Thanks in advance,
RotorTorque :)
 
something like this works for me

ds.Tables.Remove(ds.Tables(0))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top