300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > webform MySQL_asp.net webform使用MySQL数据库

webform MySQL_asp.net webform使用MySQL数据库

时间:2020-04-22 13:19:53

相关推荐

webform MySQL_asp.net webform使用MySQL数据库

前台:

table {

border:2px double red;

}

th {

border:2px double yellow;

width:100px;

color:blue;

}

td {

border:1px double yellow;

width:100px;

color:blue;

}

{%>

后台:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Configuration;

//引入MySQL的驱动

using MySql;

using MySql.Data;

using MySql.Data.MySqlClient;

namespace MySQL_Demo

{

public partial class WebForm1 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

string strcon = ConfigurationManager.AppSettings["mysqlcon"].ToString();

string sql = "select * from city";

using (MySqlConnection con = new MySqlConnection(strcon))

{

MySqlCommand cmd = new MySqlCommand();

mandText = sql;

cmd.Connection = con;

MySqlDataAdapter dr = new MySqlDataAdapter(cmd);

DataTable tb = new DataTable();

dr.Fill(tb);

Session["gtb"] = tb;//设置session,传值到前台

}

}

}

}

效果显示:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。