一、经过Visual Stdio新建.net项目html
(1)新建项目数据库
(2)选择项目配置ide
(3)项目结构工具
(4)新建一个Controller,名称要取HomeController测试
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace WebApplication1.Controllers { public class HomeController : Controller { // GET: Home public String Index() { return "Hello world"; } } }
测试:ui
二、建立ODBC数据源spa
(1)下载ODBC数据源.net
(2)配置ODBC数据源设计
添加相关的信息后点击测试:3d
三、.net链接MySQL数据库
方式一:
(1)添加引用
(2)添加一个Web窗体
(3)设计页面
选择工具:
(4)链接数据源
双击SQL数据库
(5)测试
(6)运行生成的页面便可
(7)生成的代码以下
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="students.aspx.cs" Inherits="WebApplication1.students" %> <!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></title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="stu"> <Columns> <asp:BoundField DataField="studentno" HeaderText="studentno" InsertVisible="False" SortExpression="studentno" /> <asp:BoundField DataField="birthday" HeaderText="birthday" SortExpression="birthday" /> <asp:BoundField DataField="classno" HeaderText="classno" SortExpression="classno" /> <asp:BoundField DataField="phone" HeaderText="phone" SortExpression="phone" /> <asp:BoundField DataField="sex" HeaderText="sex" SortExpression="sex" /> <asp:BoundField DataField="sname" HeaderText="sname" SortExpression="sname" /> <asp:BoundField DataField="score" HeaderText="score" SortExpression="score" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="stu" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="select *from student"> </asp:SqlDataSource> </div> </form> </body> </html>
方式二:
在配置文件中书写数据源有关的配置
<connectionStrings> <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;
Initial Catalog=aspnet-Sanlogic.MSTWebsite-20140219093639;
Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-Sanlogic.MSTWebsite-20140219093639.mdf" providerName="System.Data.SqlClient" /> <add name="DBConnection" connectionString="server=localhost; user id=root; password=root; database=student; pooling=true;" providerName="MySql.Data.MySqlClient" /> </connectionStrings>
经过读取配置文件来获取链接