Hi everyone,
I've created an application that runs queries against a SQL server (via Data Adaptors) in VB.NET 08 and returns the results to a DataGridView. It works great and returns my data, but when I switch to a different query that returns different columns, the DataGridView keeps the old columns from the previous query and adds the new columns from the new query to the end (far right) of the DataGridView. Is there a way to counter this? I don't want those previous unused columns showing up in my results.
I tried setting the DataGridView DataSource and DataMember to Nothing and that didn't fix it.
Here is my code...in case that helps
Connection.ConnectionString = "Provider=SQLOLEDB;Data Source=;Initial Catalog=;Integrated Security=SSPI;"
Connection.Open()
DataAdaptorVDN = New OleDb.OleDbDataAdapter(SQL, Connection)
DataAdaptorVDN.Fill(DataSetVDN, "VDNResults")
dgVDNResults.DataSource = DataSetVDN.DefaultViewManager
dgVDNResults.DataMember = "VDNResults"
dgVDNResults.AutoResizeColumns()
dgVDNResults.AutoResizeRows()
Next time the button is clicked this is ran before refilling the datagridview
dgVDNResults.Columns.Clear()
dgVDNResults.DataBindings.Clear()
DataSetVDN.Clear()
dgVDNResults.DataSource = Nothing
dgVDNResults.DataMember = Nothing