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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid Population Issues

Status
Not open for further replies.

Bstrick75

Programmer
Jul 22, 2002
50
0
0
US
I've looked around and haven't found a usuable solution to this issue. I hope that you can provide me with some assistance. I have a application that calls for the user to select a database/table to view data from. At that point a datagrid populates with the information. This works fine except when the user tries to either repopulate that grid with the same table or with data from a different table.

If the user tries to repopluate from the same table then if should simply overwrite what was there at first. If they try to populate from a diffferent table then it should erase the old data and input the new.

Instead what I get when i try to repopulate with the same table is that it inputs additional data starting at the last row from the frst attempt. If I am populating the grid from a new table then it will keep all the previous columns and add the new data to the last column on the left from the first attemp.

Here is my code

Dim objIntConn As New OleDbConnection
Dim objIntDataset As New DataSet
Dim objIntDataset As New DataSet

Private Sub Populate()
Try
objIntConn.Open()

objIntAdapter.SelectCommand = New OleDbCommand
objIntAdapter.SelectCommand.Connection = objIntConn
objIntAdapter.SelectCommand.CommandType = CommandType.TableDirect
objIntAdapter.SelectCommand.CommandText = cmbIntTbl.Text


Try
'objIntDataset.Reset()
'objIntDataset.Tables("IntTable").Clear()
'objIntDataset.Tables.add("IntTable")
'dgIntData.DataBindings.Clear()
Catch
End Try

objIntAdapter.Fill(objIntDataset, "IntTable")

objIntConn.Close()

dgIntData.DataSource = objIntDataset
dgIntData.DataMember = "IntTable"
dgIntData.AutoGenerateColumns = True
dgIntData.AutoResizeColumns()
Catch
MessageBox.Show("An error occured while processing data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Finally
objIntConn.Close()
End Try

You can see that I've tried a couple of different solutions and none of them have worked.


Please Help!!

Bobby Strickland
Solutions Engineer
Strictly Consulting, Inc
http:'Pleasure in the job puts perfection in the work' -- Aristotle
 
Bobby:

I've had similar issues in the past. I simply set the datasource of the datagrid to nothing before running the new data. Like this:

Code:
dgIntData.DataSource = Nothing

I hope this helps.

Ron

Ron Repp
 
I don't think that the problem is with the datagrid. I thought it was at first but I just did an experiment where I loaded the results from the reloaded values into a completely different datagrid. I had the same problems. This tells me that the problem is either with the DataAdapter, DataTable or the DataSet in general.

The problem is that I've tried everything that I can think of to clear the memory from these controls. Nothing is wrking.

Bobby Strickland
Solutions Engineer
Strictly Consulting, Inc
http:'Pleasure in the job puts perfection in the work' -- Aristotle
 
Try this:

objIntDataset.Dispose()
objIntDataset = Nothing

objIntDataset = New DataSet

objIntAdapter.Fill(objIntDataset, "IntTable")

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top