Question : Visual Basic - datagridview returns 2 rows for single database entry

Hi,
   For some reason my datagridview is returning 2 rows for each single database entry and I do not know why, this is my code:

Dim conn As MySqlConnection
        Dim MyCommand1 As New MySqlCommand
        Dim MyBuilder As New MySqlCommandBuilder
        'Dim conn As MySqlConnection
        Dim myAdapter As New MySqlDataAdapter
        Dim MyDataTable As New DataTable
        conn = New MySqlConnection()
        conn.ConnectionString = "server=server;user id=user;password=pass;database=dbname"

        Try
            conn.Open()

        Catch myerror As MySqlException
            MsgBox("Error Connecting to Database")
        End Try



        MyCommand1.CommandText = "SELECT * FROM cots_storeusers WHERE Postcode = '" + txtpostcodelookup.Text + "' OR Phone ='" + txtpostcodelookup.Text + "'"
        MyCommand1.Connection = conn
        myAdapter.SelectCommand = MyCommand1
        myAdapter.Fill(MyDataTable)
        DataGridView1.DataSource = MyDataTable

        If MyDataTable.Rows.Count = 0 Then
            MsgBox("Sorry - I can't find that postcode in the database, please try again, or add a new customer below...")
            txtpostcodelookup.Text = ""

        Else
            txtpostcodelookup.Text = ""
            myAdapter.Fill(MyDataTable)
            DataGridView1.DataSource = MyDataTable

        End If


this is what populates the grid:

            myAdapter.Fill(MyDataTable)
            DataGridView1.DataSource = MyDataTable

What am I doing wrong?

Thanks

Answer : Visual Basic - datagridview returns 2 rows for single database entry

Hi,
   I managed to fix it, I noticed I had duplicate lines of code:

myAdapter.Fill(MyDataTable)
        DataGridView1.DataSource = MyDataTable

        If MyDataTable.Rows.Count = 0 Then
            MsgBox("Sorry - I can't find that postcode in the database, please try again, or add a new customer below...")
            txtpostcodelookup.Text = ""

        Else
            txtpostcodelookup.Text = ""
            myAdapter.Fill(MyDataTable)
            DataGridView1.DataSource = MyDataTable


If you notice I have two fills on my temp table:

myAdapter.Fill(MyDataTable)

Thanks anyway, but I sorted it myself!
Random Solutions  
 
programming4us programming4us