<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ConnectMySQL.aspx.cs" Inherits="WebApplication2.ConnectMySQL" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Connect MySQL</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="grdOrders" DataSourceID ="srcOrders" runat ="server" />
<asp:SqlDataSource ID="srcOrders" ProviderName ="MySql.Data.MySqlClient" SelectCommand ="Select * from tbalarm" ConnectionString ="server=localhost;user id=root;password=mj123;database=dbmjstation; pooling=true; Charset=utf8;" runat ="server" />
</div>
</form>
</body>
</html>
<asp:SqlDataSource ID="srcOrders" ProviderName ="MySql.Data.MySqlClient" SelectCommand ="Select * from tbalarm" ConnectionString ="server=localhost;user id=root;password=mj123;database=dbmjstation; pooling=true; Charset=utf8;" runat ="server" />
SqlDataSource是不可显示的控件,可以进行属性配置,连接字符串可以百度到,其中Charset需要设置为utf8的,不然中文会显示乱码。ProviderName我这个是在属性窗口中选择的,要使用MySql.Data.MySqlClient,要查询看一下是否有该ProviderName。