2 Replies - 544 Views - Last Post: 24 August 2013 - 05:03 AM Rate Topic: -----

#1 ye_bug_me  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 30-June 12

update on mysql causes The given key was not present in the dictionary

Posted 23 August 2013 - 05:51 AM

I am facing problem on my vb.net mysql connection. I dont know if updating mysql causes the error or additional reference must be included on my project upon updating. Anyway, before I am using Mysql version 5.3.2 and everything runs well but since yesterday i decided to upgrade to new release which is MySQL Database Version 6.0.4-alpha, each time i have to connect to mysql database the error always shows up as "The given key was not present in the dictionary." I am not familiar with this error so i am stuck now searching how to solve it.

Below is my code. It is not from my actual project, i just created it to show the exact problem i am facing.

Imports MySql.Data.MySqlClient
'Imports System.IO
Public Class Form1
  Dim ms As New MySqlConnection
  Dim da As New MySqlDataAdapter
  Dim cb As New MySqlCommandBuilder
  Dim dt As New DataTable

  Sub conn()
    Try
      ms = New MySqlConnection("Server=myPC; Host=localhost; Port=3306; Database=mydb; User Id=myname; Password=getpass;")
      disc()
      ms.Open()
    Catch ex As Exception
      MsgBox("Error occurred upon connection to the main server.")
    End Try
  End Sub
  Sub disc()
    Try
      ms.Close()
    Catch ex As Exception
      MsgBox("Error occurred upon disconnection to the main server.")
    End Try
  End Sub

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Try
      Call conn()
      da = New MySqlDataAdapter("Select * from booking", ms)
      cb = New MySqlCommandBuilder(da)
      dt = New DataTable
      da.Fill(dt) ' <<--- this is the simplest way i used to fetch data and it does not 
      'return an error but now program stop executing when reading this lines. It says 
      'The given key was not present in the dictionary. I dont know what's happening on my
      'code.
      disc()
      If dt.Rows.Count() = 0 Then
        MsgBox("Zero rows added.")
      ElseIf dt.Rows.Count() > 0 Then
        MsgBox("Found Record/s")
      End If
    Catch ex As Exception
      MsgBox(ex.Message)
    End Try
  End Sub

End Class





Is This A Good Question/Topic? 0
  • +

Replies To: update on mysql causes The given key was not present in the dictionary

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3182
  • View blog
  • Posts: 10,660
  • Joined: 12-December 12

Re: update on mysql causes The given key was not present in the dictionary

Posted 23 August 2013 - 09:16 AM

I assume you need to update the MySQL driver for .NET and possibly then also update the reference to it in the project.

BTW, this

Quote

Below is my code. It is not from my actual project, i just created it to show the exact problem i am facing.

is contradictory. You should post the exact code you are using, although, of course, you might wish to to obscure confidential information. Why didn't you just copy and paste your code? (It is v. annoying for someone to study code only to discover later that it is not the real code.)
Was This Post Helpful? 0
  • +
  • -

#3 ye_bug_me  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 30-June 12

Re: update on mysql causes The given key was not present in the dictionary

Posted 24 August 2013 - 05:03 AM

Thanks for the reply and yes, I agree with you sir saying

Quote

It is v. annoying for someone to study code only to discover later that it is not the real code


but the whole code is too long, enough for someone to be confused on tracking its flow so i just briefly put the whole error issue on creating that similar project. I have considered your suggestions however when i debug it , still the program suddenly stop and point to that line.
I keep searching on net and found out that MySQL Database Version 6.0 version is really the cause. They recommend the older version of it because it is more stable. I have done that and it now works for me on vb.net and on my php site.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1