ado-的连接显示实例
从昨天晚上开始调试,终于调试成功,下面是代码。
web.config中的部分。 显示页的cs部分。using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Data.SqlClient;public partial class test : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if(!Page.IsPostBack){TestCommandReader();} } private void TestCommandReader() { String myConnectionString=ConfigurationManager.ConnectionStrings["sqlconn"].ConnectionString; SqlConnection myConn=new SqlConnection(myConnectionString); //SqlConnection myConn=new SqlConnection(myConnectionString); String cmdText="select * from geren"; SqlCommand myCommand=new SqlCommand(cmdText,myConn); try { myConn.Open(); SqlDataReader mydr=myCommand.ExecuteReader(); while(mydr.Read()) { Userlist.Items.Add(new ListItem((String)mydr["name"]));} mydr.Close(); SqlDataReader mydrOther=myCommand.ExecuteReader(); //UserOtherList.DateSource=mydrOther; UserOtherList.DataSource = mydrOther; //UserOtherList.datatextfield="name"; //UserOtherList.datavaluefield = "birthday"; //UserOtherList.databind(); //mydrOther.close(); UserOtherList.DataTextField = "name"; UserOtherList.DataValueField = "birthday"; UserOtherList.DataBind(); mydrOther.Close(); } catch(SqlException sqlex) { Response.Write(sqlex.Message+"
"); } finally{ myConn.Close(); } } protected void Userlist_SelectedIndexChanged(object sender, EventArgs e) { }}显示页aspx部分:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %> Untitled Page