ado.net的连接显示实例
来源:互联网 发布:在河里炸鱼java游戏 编辑:程序博客网 时间:2024/06/05 04:19
从昨天晚上开始调试,终于调试成功,下面是代码。
web.config中的部分。
<configuration>
<add name="sqlconn"
connectionString="server=LILIZONG;database=dangwei;uid=sa;" providerName="System.Data.SqlClient"/>
</connectionStrings>
显示页的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+"<br>");
}
finally{
myConn.Close();
}
}
protected void Userlist_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
显示页aspx部分:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ListBox ID="Userlist" runat="server" Height="400px" Width="300px">
</asp:ListBox>
<asp:ListBox ID="UserOtherList" runat="server" Height="400px" Width="300px" ></asp:ListBox>
</form>
</body>
</html>
- ado.net的连接显示实例
- ADO.NET的连接
- ADO.NET连接Access数据库实例
- Ado.net的连接池
- ADO.net 的连接池
- ADO.NET的连接字符串
- ADO.NET 的最全实例,Ado.Net最佳使用方法 ADO.NET 的最佳实践技巧
- 关于C# Ado.NET连接数据库操作基本实例模板
- ADO.NET、JDBC连接Sql Server2008简单实例
- Sql server的odbc,ado,ado.net连接串.
- ADO.NET下的各种连接字符串
- Access数据库的连接(ADO.NET)
- ADO.NET与各种数据库的连接
- ADO.NET连接数据库的命令格式
- 关于ADO.NET连接数据库的问题
- ado.net连接数据库的用法
- .Net的ADO连接数据库知识小结
- ADO.NET实例代码
- owc组件使用(统计分析图)
- ado.net数据库连接
- [LUA学习笔记04]Lua语法--数据类型
- Java SE 6之脚本引擎 让程序如虎添翼
- 帮助寻找图灵奖得主Jim Gray
- ado.net的连接显示实例
- winpcap一些开发实践
- Windows XP 的系统和局部环境变量
- 1.31晴 感冒中
- VC中隐式链接无.LIB动态链接库的方法
- 给数据库用户设置存储过程执行权限的SQL语句
- CSDN的Blog为什么总是报错呢?郁闷……
- 研一的生活
- Java SE6调用Java编译器的两种新方法