|
-
Aug 21st, 2007, 07:57 AM
#1
Thread Starter
Hyperactive Member
[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
-
Aug 21st, 2007, 09:23 AM
#2
Thread Starter
Hyperactive Member
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?
-
Aug 21st, 2007, 10:43 AM
#3
Thread Starter
Hyperactive Member
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?
-
Aug 21st, 2007, 04:06 PM
#4
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.
-
Aug 21st, 2007, 04:14 PM
#5
Fanatic Member
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.
-
Aug 22nd, 2007, 03:04 AM
#6
Thread Starter
Hyperactive Member
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.
-
Aug 22nd, 2007, 03:29 AM
#7
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|