DataGrid and mysql in vbnet

Asso79

Active member
Joined
Jun 6, 2003
Messages
35
I want populate a datagrid with a dbase mysql but i have an error with sqldataadapter. This connection with insert and select in combobox its ok but i dont use sqldataadapter, its only for datagrid.

An unhandled exception of type System.ArgumentException occurred in system.data.dll

Additional information: Unknown connection option in connection string: driver.

Code:
Dim sConn As String = "Driver=MySQL ODBC 3.51 Driver; Database=dbase;dsn=dsn;uid=;password=;"
Dim SQL As String = "SELECT * FROM vari"
Dim objConn As New OdbcConnection(sConn)
Dim objCommand As New OdbcCommand(SQL, objConn)
Dim objdataadapter As New OdbcDataAdapter(SQL, objConn)

Try
objConn.Open()
Catch excep As System.Exception
Windows.Forms.MessageBox.Show(excep.Message)
End Try

Dim dataAd As New SqlDataAdapter(SQL, sConn)
[-vb]
 
try with ODBC driver 2.50 , because i have problems with update command,connection and some other stuff while i used ODBC 3.51.....


Code:
ODBC 3.51
Dim sConn As String = "Provider=MSDASQL.1;Driver=MySQL ODBC
 3.51 Driver; Database=dbase;dsn=dsn;uid=;password=;"

Code:
ODBC 2.50
Dim sConn As String = "Provider=MSDASQL.1;Driver={MySQL}; 
Database=dbase;dsn=dsn;uid=;password=;"


also after you establish connection ( :D )
i) you have to download hotfix from Microsoft site otherwise
while fetching empty string (0 length), will give SQL_NO_DATA exception

ii) Install Microsoft Data Access Components (MDAC) 2.6 or later. MDAC 2.7 is recommended.
 
Last edited by a moderator:
ADDITION TO PREV POST !!!!

iii) if you define your connection over ODBC DSN (as i see you did that -->DSN=dsn ) you dont need any parametar in your connection except DSN because you described all this params ( user,pass,server,bla ) in ODBC DSN!!!

Example:

Code:
Dim sConn As String = "dsn=dsn"
 
i try with only
VB:
--------------------------------------------------------------------------------
Dim sConn As String = "dsn=dsn"

--------------------------------------------------------------------------------
but the error its an error in SqlDataAdapter


an unhandled exception of type System.ArgumentException occurred in system.data.dll

Additional information: Unknown connection option in connection string: dsn.

while

VB:
--------------------------------------------------------------------------------
ODBC 3.51
Dim sConn As String = "Provider=MSDASQL.1;Driver=MySQL ODBC
3.51 Driver; Database=dbase;dsn=dsn;uid=;password=;"

--------------------------------------------------------------------------------

The error is
An unhandled exception of type System.ArgumentException occurred in system.data.dll

Additional information: Unknown connection option in connection string: provider.
 
SqlDataAdapter is for MSSQL and you are not using MSSQL

Code:
Dim dataAd As New SqlDataAdapter(SQL, sConn)


for mySQL try with:

Code:
Dim dataAd As New OdbcDataAdapter(SQL,SConn)



:D
 
Last edited by a moderator:
if you want use dsn( only ) in your connection string before you
can use it you must declare it.


i) Control panel-->Administrative tools-->Data Sources ODBC
ii) Add
iii) pick mySql driver
iv) provide information for your connection (dsn
name,pass,user,database,.......)
v) type in vb
Code:
String myConn ="dsn=name that you provided in step iv) for dsn 
name(exactly)"

:D
 
Last edited by a moderator:
Its ok i tried with
Dim objdataadapter As New OdbcDataAdapter(SQL, objConn)
and to associate the query with datagrid i write the code:

Code:
objdataadapter.SelectCommand.CommandText = "use dbasemysql;"
objdataadapter.SelectCommand.ExecuteNonQuery()

objdataadapter.SelectCommand.CommandText = SQL
DataGrid1.DataSource = objdataadapter.SelectCommand.ExecuteNonQuery()
[-vb]

The error is:
Additional information: Complex DataBinding accepts as a data source either an IList or an IListSource.

with only dsn=..... is equal.
 
CORRECT

try with this:
Code:
DIm myTable as DataTable("Table")
objdataadapter.Fill(myTable)
DataGrid1.DataSource = myTable
 
Its dont recognized:
Dim myTable As DataTable("Client")
i try with Client and Table but not accept string
 
hehe


Code:
Dim myTable As New DataTable("table")
    Dim myConn As New OdbcConnection("provider=MSDASQL;driver={MySQL};server=MYCOMP;user=;pass=;database=wbamar")
    Dim myAdap As New OdbcDataAdapter()




    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            myConn.Open()
        Catch errobj As Exception
            MessageBox.Show(errobj.Message)

        End Try
        myAdap.SelectCommand = New OdbcCommand("SELECT * FROM sifrant")
        myAdap.SelectCommand.Connection = myConn
        myAdap.Fill(myTable)
        DataGrid1.DataSource = myTable

    End Sub

here is the code that works to me, just put your connection parameters and query!!!
 
Back
Top