C# BulletedList 绑定 Mysql
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 MySql.Data.MySqlClient; public partial class page1 : System.Web.UI.Page { string connStr = String.Format( "server={0};user id={1};password={2};database={3};port={4};pooling=false;charset=utf8", "192.168.1.3", "root", "1234567", "test", 3306); public MySqlConnection con = new MySqlConnection(); public MySqlDataAdapter da; public MySqlCommandBuilder cb; public MySqlCommand cmd; public MySqlDataReader dr; protected void Page_Load(object sender, EventArgs e) { con.ConnectionString = connStr; try { con.Open(); Label1.Text = "连接 Mysql 成功!"; string sql = "select * from test"; da = new MySqlDataAdapter(sql, con); DataSet mydataset = new DataSet(); da.Fill(mydataset, "test"); BulletedList1.DataSource = mydataset.Tables["test"]; BulletedList1.DataTextField = "Name"; BulletedList1.DataValueField = "link"; BulletedList1.DataBind(); } catch { Label1.Text = "连接 Mysql 失败!"; } } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。