Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am really getting confused. I could connect mysql successfully in one windows application form. But same code I cannot do in other windows form!!!!


VB
Imports MySql.Data
Imports MySql.Data.MySqlClient

Public Class mysqltblinsert
   Dim cont As Mysqlconnnection

   Try

      cont = New MySqlConnection

      cont.ConnectionString = "server=localhost;user id=root;password=xxx;database=mydatabase1;"
      cont.Open()
      Dim str As String = "select * from mydatabase1.tblemp; "
      Dim da As New MySqlDataAdapter("select * from tblemp;", cont)
      Dim ds As New DataSet
      da.Fill(ds, "tblemp")
      cont.Close()
      DGV.DataSource = ds.Tables("tblemp")


   Catch ex As Exception
      MessageBox.Show(ex.Message)

   End Try

End Sub


Error   1   Value of type 'MySql.Data.MySqlClient.MySqlConnection' cannot be converted to 'codeprojects.Mysqlconnnection'.
Error   2   'ConnectionString' is not a member of 'codeprojects.Mysqlconnnection'.
Error   3   'Open' is not a member of 'codeprojects.Mysqlconnnection'
Error   4   Overload resolution failed because no accessible 'New' can be called with these arguments:
    'Public Sub New(selectCommandText As String, selectConnString As String)':
Posted
Updated 9-Jun-15 3:08am
v2
Comments
CHill60 9-Jun-15 9:12am    
Try changing Dim cont As Mysqlconnnection to Dim cont As MySqlConnnection
Kornfeld Eliyahu Peter 9-Jun-15 9:37am    
Why not an answer? (C# after all is case sensitive and all should know it!)
CHill60 9-Jun-15 9:40am    
Will do now member has confirmed error has gone.
Member 11749706 9-Jun-15 9:43am    
but it is vb.net which is not case sensitive na
CHill60 9-Jun-15 10:04am    
It is case-sensitive but usually the IDE will correct that on your behalf. In this case you have 3 'n' in "connnection".

1 solution

Problem is in the line
VB
Dim cont As Mysqlconnnection
Clue is in the first error message
Quote:
Value of type 'MySql.Data.MySqlClient.MySqlConnection' cannot be converted to 'codeprojects.Mysqlconnnection'
Note the case of the letters. Use
VB
Dim cont As MySqlConnection
All of the other errors (as listed) will then go away. Note - this is often the case, always attempt to fix the first problem reported and then review the error list.
 
Share this answer
 
v2
Comments
Member 11749706 9-Jun-15 9:43am    
thanks dear
Kornfeld Eliyahu Peter 9-Jun-15 9:52am    
Just noticed the reason the IDE didn't fixed case (as usually does in VB.NET)
Mysqlconnnection has 3 n in it!!!
(fixed your code - I hope you don't care)
CHill60 9-Jun-15 9:56am    
Good spot!! I have absolutely no problems with you fixing the solution.

I did wonder ... as you say, Visual Studio is far more forgiving and (in my case) corrects bad casing. A virtual 5 to you! I'm off to the optician now :)
Member 11749706 9-Jun-15 9:58am    
can you please help me in this error : http://www.codeproject.com/Questions/999088/connect-sqlserver-through-app-config?arn=0
Member 11749706 9-Jun-15 9:54am    
i could fix it but why no read line came..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900