|
| Connect Asp.net to MySQL and retrieve data |
 |
Sun, 16 Mar 2008 08:41:39 +000 |
halo everyone. i'm new to asp.net
i have install MySQL 5.0 as database and already install MySQL connector/ODBC
3.51 and MYSQL server 5.0
i try with the connection code to retrieve data as below
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.ODBC" %>
<script language="VB" Runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim myConnection As OdbcConnection
Dim myCommand As OdbcDataAdapter
' Create a connection to the "pubs" SQL database located on
the
' local computer.
myConnection = New OdbcConnection("server=localhost;" _
& "database=db;USER=root;PASSWORD=860216; OPTION=3;")
' Connect to the SQL database using a SQL SELECT query to get all
' the data from the "Titles" table.
myCommand = New OdbcDataAdapter("SELECT * FROM user",
myConnection)
' Create and fill a DataSet.
Dim ds As DataSet = New DataSet()
myCommand.Fill(ds)
' Bind MyDataList to the DataSet. MyDataList is the ID for
' the DataList control in the HTML section of the page.
MyDataList.DataSource = ds
MyDataList.DataBind()
End Sub
</script>
And i try to display the data with:
<ASP:DataList id="MyDataList" RepeatColumns="2"
RepeatDirection="Horizontal" runat="server">
<ItemTemplate>
<div
style="padding:15,15,15,15;font-size:10pt;font-family:Verdana">
<br>
<b>User: </b>
<%#DataBinder.Eval(Container.DataItem,
"Username")%><br>
<b>Pw: </b>
<%#DataBinder.Eval(Container.DataItem,
"Password")%><br>
<b>Publisher ID: </b>
</div>
</ItemTemplate>
</ASP:DataList>
After running, it doesn't show any error. But there was no result display. What
i get is just an empty page.
Can anyone help???
|
| Post Reply
|
| Re: Connect Asp.net to MySQL and retrieve data |
 |
Sun, 16 Mar 2008 12:21:37 +000 |
Try:
myConnection = New OdbcConnection("Driver={MySQL ODBC 3.51
Driver};server=localhost;database=db;uid=root;pwd=860216; OPTION=3;")
Just to check, is there any data in the table, user?
|
| Post Reply
|
| Re: Connect Asp.net to MySQL and retrieve data |
 |
Sun, 16 Mar 2008 12:54:20 +000 |
There was a few data in that table
|
| Post Reply
|
| Re: Connect Asp.net to MySQL and retrieve data |
 |
Sun, 16 Mar 2008 15:14:28 +000 |
it give me the same result... that is an empty page.
is it that if i use microsoft visual web developer to do the asp.net
application, then i must connect only to the database such as ms sql and access
only?
or i nit to add any driver to the application so it only can work well??
|
| Post Reply
|
| Re: Connect Asp.net to MySQL and retrieve data |
 |
Sun, 16 Mar 2008 15:30:46 +000 |
Is there any data in the user table?
|
| Post Reply
|
|
|
|
|
|
|
|
|
|