Home All Groups Group Topic Archive Search About

Datagridview -- Won't Clear

Author
20 Dec 2006 5:52 PM
Arne Beruldsen
I have a Datagridview which populates fine...but when I refine the data...the
subsequent searches are added to the end.  I can't seem to claer the grid
with only the new info.

My code...

Private Sub GetData(ByVal selectCommand As String)
        Try
            SxAdapter = New OleDbDataAdapter(selectCommand, CS)
            Dim MyCommandBuilder As New OleDbCommandBuilder(SxAdapter)
            SxTable.Locale = System.Globalization.CultureInfo.InvariantCulture
            Me.SxAdapter.Fill(SxTable)
            Me.SxSource.DataSource = SxTable
        Catch ex As OleDbException
            MessageBox.Show("Error")
        End Try
    End Sub

Me.DataGridView1.DataSource = Nothing
        Me.DataGridView1.Rows.Clear()
        Me.DataGridView1.DataSource = SxSource
        GetData("Select LastName, FirstName, TestName,TestDate, Score, ID
from TestScores where TestName ='" & ListBoxControl3.Text & "' ")
        Me.DataGridView1.Update()

What am I doing wrong?

Author
21 Dec 2006 5:29 AM
Cor Ligthert [MVP]
Arne,

Probably is it because youi clear nowhere that SXTable.

SXTable.clear.

Cor

Show quoteHide quote
"Arne Beruldsen" <ArneBeruld***@discussions.microsoft.com> schreef in
bericht news:BEFF1675-E44E-4838-B00F-A52C42DD2853@microsoft.com...
>I have a Datagridview which populates fine...but when I refine the
>data...the
> subsequent searches are added to the end.  I can't seem to claer the grid
> with only the new info.
>
> My code...
>
> Private Sub GetData(ByVal selectCommand As String)
>        Try
>            SxAdapter = New OleDbDataAdapter(selectCommand, CS)
>            Dim MyCommandBuilder As New OleDbCommandBuilder(SxAdapter)
>            SxTable.Locale =
> System.Globalization.CultureInfo.InvariantCulture
>            Me.SxAdapter.Fill(SxTable)
>            Me.SxSource.DataSource = SxTable
>        Catch ex As OleDbException
>            MessageBox.Show("Error")
>        End Try
>    End Sub
>
> Me.DataGridView1.DataSource = Nothing
>        Me.DataGridView1.Rows.Clear()
>        Me.DataGridView1.DataSource = SxSource
>        GetData("Select LastName, FirstName, TestName,TestDate, Score, ID
> from TestScores where TestName ='" & ListBoxControl3.Text & "' ")
>        Me.DataGridView1.Update()
>
> What am I doing wrong?
Author
21 Dec 2006 2:21 PM
Arne Beruldsen
Thanks...that did the trick...

Show quoteHide quote
"Cor Ligthert [MVP]" wrote:

> Arne,
>
> Probably is it because youi clear nowhere that SXTable.
>
> SXTable.clear.
>
> Cor
>
> "Arne Beruldsen" <ArneBeruld***@discussions.microsoft.com> schreef in
> bericht news:BEFF1675-E44E-4838-B00F-A52C42DD2853@microsoft.com...
> >I have a Datagridview which populates fine...but when I refine the
> >data...the
> > subsequent searches are added to the end.  I can't seem to claer the grid
> > with only the new info.
> >
> > My code...
> >
> > Private Sub GetData(ByVal selectCommand As String)
> >        Try
> >            SxAdapter = New OleDbDataAdapter(selectCommand, CS)
> >            Dim MyCommandBuilder As New OleDbCommandBuilder(SxAdapter)
> >            SxTable.Locale =
> > System.Globalization.CultureInfo.InvariantCulture
> >            Me.SxAdapter.Fill(SxTable)
> >            Me.SxSource.DataSource = SxTable
> >        Catch ex As OleDbException
> >            MessageBox.Show("Error")
> >        End Try
> >    End Sub
> >
> > Me.DataGridView1.DataSource = Nothing
> >        Me.DataGridView1.Rows.Clear()
> >        Me.DataGridView1.DataSource = SxSource
> >        GetData("Select LastName, FirstName, TestName,TestDate, Score, ID
> > from TestScores where TestName ='" & ListBoxControl3.Text & "' ")
> >        Me.DataGridView1.Update()
> >
> > What am I doing wrong?
>
>
>