把数据库中的数据读出来并用BulletedList控件来显示

it2022-05-21  75

需要在前台加上BulletedList控件,如果需要什么设置自己在前台改一下就行

string connStr = @"data source=.;initial catalog=Study_.net;user id=sa;password=123";//数据库连接字符串                SqlConnection conn1 = new SqlConnection(connStr);                conn1.Open();//打开连接                SqlCommand cmd = conn1.CreateCommand();                cmd.CommandText = "select * from top0 where(topDesc like'%" + Session["text"].ToString() + "%')";//这个是模糊查询                DataSet ds = new DataSet();                SqlDataAdapter adapter = new SqlDataAdapter(cmd);                adapter.Fill(ds);                cmd.ExecuteNonQuery();                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)                {                    string desc = ds.Tables[0].Rows[i]["topDesc"].ToString();                    string url = ds.Tables[0].Rows[i]["topUrl"].ToString();                    ListItem list = new ListItem(desc, url);                    BulletedList1.Items.Add(list);                }

转载于:https://www.cnblogs.com/qzc900809/archive/2013/01/05/2846378.html

相关资源:数据结构—成绩单生成器

最新回复(0)