Results 1 to 7 of 7

Thread: [2005] Bind gridView with MySQL

  1. #1

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    [2005] Bind gridView with MySQL

    Hello.
    I'm trying to bind a griidview with some MySQL data. I'm using Visual WebDeveloper 2005 Express.

    What I do is, create a general function to handle the connections and all that kind of stuf, then, I send to the gridview.DataSource the function, wich will return a dataset.

    What happens is that i an't see any data in the gridview.
    Can anybody help me?

    Thanks in advance.

    Code:
    Public Class acessos
        Public num_registos As Integer
        Public VectForm(2048) As Boolean
    
        Public User As String = "root"
        Public Password As String = "admin"
        Public servidor As String = "localhost"
        Public BD As String = "radioportal"
    
    
    
        Public Function AbreDataSet(ByVal strSQL As String, ByVal Tabela As String) As Data.DataSet
            Dim ds As Data.DataSet
            Dim DataAdapt As Data.Odbc.OdbcDataAdapter
            Dim ConnString As String = _
                                "driver={MySQL ODBC 3.51 Driver};server=" & servidor & _
                                ";uid=" & User & _
                                ";pwd=" & Password & _
                                " ;database=" & BD
    
    
            Dim conn As New Data.Odbc.OdbcConnection(ConnString)
    
            Try
    
                DataAdapt = New Data.Odbc.OdbcDataAdapter(strSQL, ConnString)
                ds = New Data.DataSet
    
                conn.Open()
                DataAdapt.Fill(ds, Tabela)
                num_registos = ds.Tables(0).Rows.Count.ToString() 
    
                Return ds
    
            Catch exx As Exception
                'MsgBox(exx.Message & Chr(13), MsgBoxStyle.Information)
            End Try
    
            'Return ds
    
        End Function
    
    '------------------------------------------
    '  
    '------------------------------------------
        Dim acc As New acessos
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim strSQL As String = "Select * from utilizadores"
            Me.GridView1.DataSource = acc.AbreDataSet(strSQL, "utilizadores")   'definir o DataSet a abrir
            Me.GridView1.DataMember = "utilizadores"
        End Sub

  2. #2

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005] Bind gridView with MySQL

    Meanwhile, i removed the error handler and I got this error:

    ERROR [HY000] [MySQL][ODBC 3.51 Driver]Unknown MySQL server host 'localhost ' (11001)
    ERROR [HY000] [MySQL][ODBC 3.51 Driver]Unknown MySQL server host 'localhost ' (11001)

    What's happening?

  3. #3

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005] Bind gridView with MySQL

    I've beern using a very similar class in .net 2003 and it was running pretty good. What may have changed so much that i cant connect to server?

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Bind gridView with MySQL

    After setting Datasource & Datamember properties you have to call gridview.DataBind() method for the data to show on the gridview. For the error, double check your connection string... Frankly, I would use OleDb driver instead of ODBC.

  5. #5
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668

    Re: [2005] Bind gridView with MySQL

    RS_Arm, open up a command window (run -> cmd.exe) and type:

    telnet localhost 3306

    Do you get the same error?
    If wishes were fishes we'd all cast nets.

  6. #6

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005] Bind gridView with MySQL

    No. What I get is this message:

    E
    5.0.24-community-nt-log☺*Jr$Ucq0,☻8i+7pQ&dHzNX

    Should this happens?

    Thanks you.

  7. #7

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: [2005] Bind gridView with MySQL

    stanav, i've included to my code the "gridview.DataBind()" method. Still the same.
    Why do you think I should use OleDb instead ODBC?
    Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width