By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,899 Members | 1,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,899 IT Pros & Developers. It's quick & easy.

data mismatch in critical expression

P: 1
Expand|Select|Wrap|Line Numbers
  1. Private Sub DataGridView1_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
  2.         Try
  3.             Dim dt As New DataTable
  4.             'Dim dr As DataRow
  5.          dp = "Provider=Microsoft.Jet.OLEDB.4.0;"
  6.         src = "Data source=c:\Database\licdb.mdb"
  7.             con.ConnectionString = dp & src
  8.             con.Open()
  9.             'db()
  10.             query = "select * from year2008 where id = '" & id & "'"
  11.             da = New OleDb.OleDbDataAdapter(query, con)
  12.             da.Fill(ds1, "tab")
  13.             da.Fill(dt)
  14.  
  15.             TextBox1.Text = ds1.Tables("tab").Rows(id).Item(1).ToString()
  16.             TextBox2.Text = ds1.Tables("tab").Rows(id).Item(2).ToString()
  17.             TextBox3.Text = ds1.Tables("tab").Rows(id).Item(3).ToString()
  18.             TextBox4.Text = ds1.Tables("tab").Rows(id).Item(4).ToString()
  19.             TextBox5.Text = ds1.Tables("tab").Rows(id).Item(5).ToString()
  20.             TextBox14.Text = ds1.Tables("tab").Rows(id).Item(6).ToString()
  21.             TextBox7.Text = ds1.Tables("tab").Rows(id).Item(7).ToString()
  22.             TextBox8.Text = ds1.Tables("tab").Rows(id).Item(8).ToString()
  23.             TextBox9.Text = ds1.Tables("tab").Rows(id).Item(9).ToString()
  24.             TextBox10.Text = ds1.Tables("tab").Rows(id).Item(10).ToString()
  25.             TextBox16.Text = ds1.Tables("tab").Rows(id).Item(11).ToString()
  26.             TextBox11.Text = ds1.Tables("tab").Rows(id).Item(12).ToString()
  27.             TextBox17.Text = ds1.Tables("tab").Rows(id).Item(13).ToString()
  28.             con.Close()
  29.         Catch ex As Exception
  30.             MsgBox(ex.Message, MsgBoxStyle.Critical)
  31.             Me.Close()
  32.         End Try
  33.  
  34.     End Sub
Oct 26 '13 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,035
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 .....
Oct 26 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.