XSD数据集

Part1:添加SQL语句查询
A。新建项目-ASP.NET AJAX-Enabled Web Application。
B。添加-新建项-数据集。
C。双击打开xsd,右键-添加-TableAdapter:选择连接-使用SQL-查询生成器-添加要查询的表和字段(如Blog_Video)-返回DataTable。
     //DataSet1.xsd中可以存在多个TableAdapter(对应多个表),一般命名成模块或功能的名字,如BlogFileData.xsd。
     //添加查询可以选择“使用现有存储过程”,返回“表格数据”。
D。右键“BLOG_VIDEOTableAdapter”-添加查询-使用SQL-Select返回行,SQL语句可加入参数做为查询条件,如Where VideoId = :VideoIdParam-
     返回DataTable,方法名设  为GetDataByVideoId。
     //添加完后.NET自动生成DataSet1.Designer.cs代码
E。用GridView做绑定测试。aspx.cs:
    DataSet1TableAdapters.BLOG_VIDEOTableAdapter BlogVideoAdapter = new AJAXEnabledWebApplication1.DataSet1TableAdapters.BLOG_VIDEOTableAdapter();
    GridView1.DataSource = BlogVideoAdapter.GetDataByVideoId(1001);  //传入参数
    GridView1.DataBind();

Part2:添加存储过程查询
A。创建包
create or replace package types
as
type cursorType is ref cursor;
end types;

B。创建存储过程
Create or Replace Procedure proGetTopNews
(
 vEndIndex in decimal,
 vUserName in nvarchar2,
 orows out types.cursorType /*包名.属性*/
)
is
Begin
Open orows For
Select NewsId,NewsData,OtherColumns
From (Select NewsId,NewsData,OtherColumns From News Where UserName = vUserName Order By CreateDate DESC)
Where rownum <= vEndIndex;
End proGetTopNews;

C。添加数据集
在项目引用的类库(如MyLib)中添加数据集(DataSet1.xsd),为数据集添加查询:添加查询-使用现有的存储过程-proGetTopNews-表格数据-返回DataTable,方法名GetTopNews。

D。页面显示:
测试页Default.aspx中引入命名空间:using MyLib; 编写DataBind绑定函数。
private void BindData()
{
 MyLib.DataSet1TableAdapters.BLOG_POSTTableAdapter _adapter = new MyLib.DataSet1TableAdapters.BLOG_POSTTableAdapter();
 object obj;
  GridView1.DataSource = _adapter.GetTopNews(10, "Terry", out obj); //取出Terry的博客最新前十条新闻
  GridView1.DataBind();
}
PS:数据集(xsd)添加查询提示:新命令文本所返回数据的架构与主查询的架构不同 http://www.mzwu.com/article.asp?id=2198 

原文地址:https://www.cnblogs.com/vipcjob/p/1553820.html