data mismatch in critical expression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prince19592
    New Member
    • Oct 2013
    • 1

    data mismatch in critical expression

    Code:
    Private Sub DataGridView1_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
            Try
                Dim dt As New DataTable
                'Dim dr As DataRow
             dp = "Provider=Microsoft.Jet.OLEDB.4.0;"
            src = "Data source=c:\Database\licdb.mdb"
                con.ConnectionString = dp & src
                con.Open()
                'db()
                query = "select * from year2008 where id = '" & id & "'"
                da = New OleDb.OleDbDataAdapter(query, con)
                da.Fill(ds1, "tab")
                da.Fill(dt)
    
                TextBox1.Text = ds1.Tables("tab").Rows(id).Item(1).ToString()
                TextBox2.Text = ds1.Tables("tab").Rows(id).Item(2).ToString()
                TextBox3.Text = ds1.Tables("tab").Rows(id).Item(3).ToString()
                TextBox4.Text = ds1.Tables("tab").Rows(id).Item(4).ToString()
                TextBox5.Text = ds1.Tables("tab").Rows(id).Item(5).ToString()
                TextBox14.Text = ds1.Tables("tab").Rows(id).Item(6).ToString()
                TextBox7.Text = ds1.Tables("tab").Rows(id).Item(7).ToString()
                TextBox8.Text = ds1.Tables("tab").Rows(id).Item(8).ToString()
                TextBox9.Text = ds1.Tables("tab").Rows(id).Item(9).ToString()
                TextBox10.Text = ds1.Tables("tab").Rows(id).Item(10).ToString()
                TextBox16.Text = ds1.Tables("tab").Rows(id).Item(11).ToString()
                TextBox11.Text = ds1.Tables("tab").Rows(id).Item(12).ToString()
                TextBox17.Text = ds1.Tables("tab").Rows(id).Item(13).ToString()
                con.Close()
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Critical)
                Me.Close()
            End Try
    
        End Sub
    Last edited by Rabbit; Oct 26 '13, 09:20 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    When you do this:
    query = "select * from ......

    You will never KNOW how much columns will be returned from the database, you should therefore use the proper columnnames, and not '*'
    query = "select column1, column2, .... from .....

    Comment

    Working...