人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

May 29, 2006

webcast_How do I Video Series_Data Access

Filed under: ASP.NET

How do I? Video Series : Data Access(hilo_data_final.wmv)
http://asp.net/default.aspx?tabindex=4&tabid=3000
http://asp.net/learn/howdoi/default.aspx?tabid=63

共14分钟,演示了
1. 使用mdf文件, 从pubs数据库authots表导入数据

2. 生成了数据访问层: 生成connection string , 生成和配置 dataset,

3. 针对dataset的data binding
共两个页面: default.aspx 和 details.aspx

defautl 页面上有一个combo box, 一个gridview,演示了级联数据显示.
        gridview 还添加了detail url,指向 details页面,显示详细信息.

details页面,使用了DetailsView, 根据url中传来的参数,显示详细信息.

详细步骤:
//—-使用mdf文件
1. 在vs 2005 中可以直接生成mdf文件, 生成table,但不能执行 create table 等sql语句.
使用 SQL Server Management Studio Attach上mdf文件,可进行高级操作

//—-操作dataset
dataset会被存放在app_code目录中

可把table或table中的field从db explorer上drag到date set的design view上来生成table adapter

按照Table Adapter Configuration的提示可生成connection string 和用于select, update, delete
的sql 语句.
select 语句的where 子句通过设置filter 来实现,比如把filter设为 Filter = @state,会生成语句
where(state = @state)

完成后可使用preview data 菜单来进行测试, Cool!

//—- data binding
使用dataset,要在为control设置数据源时,选择object.
combo box 用来显示state,并用于引发dataview的变化, 所以combo box 的"Enable AutoPostback" 要设为true.
注意data source 的参数可以来自其他control, 也可以来自url.
把一个page drag到另一个page上可以直接生成一个link.

//如何实现details page
1.给data view添加一个column
2.设置column类型为HyperLinkField
3.设置HyperLink URL
  get url from data field : authorId
  url fromat string : Detauls.aspx?AuthorId={0}
4.在DataSet中添加一个query: GetDataByAuthorID
5.生成details page,添加DetailsView,设置datasource 为object,
  设置Parameter source为QueryString, QueryStringField为AuthorId
  和dataview的HyperLink column的设置对应.

Comments »

The URI to TrackBack this entry is: http://recordsome.blogsome.com/2006/05/29/webcast_how-do-i-video-series_data-access/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham