<%@ 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。