Skip to content

Connecting MySQL with ASP.NET (VB)

February 19, 2007

<%@ Page Language=”VB” AutoEventWireup=”False”
EnableSessionState=”False” EnableViewState=”False” %>
<%@ Import Namespace=”System.Data” %>
<%@ Import Namespace=”System.Data.Odbc” %>

<%
Dim ConnStr As String = “Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=test;uid=root;pwd=passwordhere;option=3”
Dim con As OdbcConnection = New OdbcConnection(ConnStr)
Dim cmd As OdbcCommand = New OdbcCommand(“SELECT * FROM Names”, con)
con.Open()
dgrAllNames.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection Or CommandBehavior.SingleResult)
dgrAllNames.DataBind()
%>

<html>
<head>
<title>Displaying Records from MySQL ‘Names’ table</title>
<style>
body { font: 100% Verdana; }
</style>
</head>
<body>

<p align=”center”>All records in the ‘Names’ table:</p>

<asp:DataGrid ID=”dgrAllNames” HorizontalAlign=”Center”
CellPadding=”3″ Runat=”server” />

</body>
</html>

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: