ado.net的连接显示实例

网友投稿 585 2022-12-02

ado-的连接显示实例

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

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:数字水印综述
下一篇:EF学习笔记——通用增删改查方案
相关文章

 发表评论

暂时没有评论,来抢沙发吧~