简答使用可以看https://www.cnblogs.com/namejr/p/10411920.html中的“先来简单介绍dataset和datatable”

DataSet强类型:

WebForm1.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" />
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Button" />
     <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><asp:Button ID="Button4" runat="server" Text="Button" OnClick="Button4_Click" />
     <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><asp:Button ID="Button5" runat="server" Text="Button" />
</form>
</body>
</html>
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
WebForm1.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
// 数据查询
ProductDataSet ds = new ProductDataSet();
var daProduct = new ProductDataSetTableAdapters.ProductTableAdapter(); // 默认使用了getDate()方法
var daCategory = new ProductDataSetTableAdapters.CategoryTableAdapter();
daProduct.Fill(ds.Product);
daCategory.Fill(ds.Category);
// 数据绑定显示
this.GridView1.DataSource = ds.Product;
this.GridView2.DataSource = ds.Category;
this.DataBind();
} protected void Button2_Click(object sender, EventArgs e)
{
// 插入数据
new ProductDataSetTableAdapters.CategoryTableAdapter().Insert(, "平板");
// 同理,还有delete、Update
} protected void Button3_Click(object sender, EventArgs e)
{
// 除了上面的Button2里面的增删改查操作,还有下面这些方法
ProductDataSet ds = new ProductDataSet();
var daCategory = new ProductDataSetTableAdapters.CategoryTableAdapter();
daCategory.Fill(ds.Category);
/* 删除
ds.Category.FindByCategoryID(2).Delete(); // 根据CategoryID进行删除
ds.Category.RemoveCategoryRow(ds.Category.FindByCategoryID(2)); // 进行先查找row在根据ID进行删除
*/
/* 添加
ds.Category.AddCategoryRow(4, "图书");
var newRow = ds.Category.NewCategoryRow();
newRow.CategoryID = 5;
//newRow.CategoryName = "视频";
newRow["CategoryName"] = "视频";
ds.Category.AddCategoryRow(newRow);
*/
var oldRow = ds.Category.FindByCategoryID();
oldRow.CategoryName = "cellPhone";
daCategory.Update(ds.Category);
}

      protected void Button4_Click(object sender, EventArgs e)
      {
        // 显示自定义的配置
        this.Label1.Text = string.Format("{0}", new ProductDataSetTableAdapters.CategoryTableAdapter().ScalarQueryCount().Value);
      }

      protected void Button5_Click(object sender, EventArgs e)
      {
        // 关联配置的显示(外键)
        ProductDataSet ds = new ProductDataSet();
        var daProduct = new ProductDataSetTableAdapters.ProductTableAdapter();
        var daCategory = new ProductDataSetTableAdapters.CategoryTableAdapter();
        daProduct.Fill(ds.Product);
        daCategory.Fill(ds.Category);
        var Product = ds.Product.FindByProductID(2); // 获取对应的product的对应的索引
        var category = Product.CategoryRow; // 进行关联
        this.Label2.Text = string.Format("商品:{0}的类别是{1}", Product.ProductNAME, category.CategoryName);
      }

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
ProcudtDataSet1.xsd
构建这个东西只需要进行右键添加“数据集(DataSet1.xsd)”,将名字修改为对应数据库表的前缀即可。
关于构建的两种方法:一种是使用tableAdapter进行配置;另一种是直接将数据库表直接拖拽过来即可(拖拽过来的好处是会直接显示对应的关联关系)
如果自己有需要,可以根据用户的需求进行配置SQL查询语句,例如本例子中,可以进行右键“CategoryTableAdapter”进行添加(如添加查询)或者配置设计

DataSet强类型、TableAdapter的使用的更多相关文章

  1. LINQ(LINQ to DataSet)

    http://www.cnblogs.com/SkySoot/archive/2012/08/21/2649471.html DataTable.Select()方法使用和 SQL 相似的过滤语法从 ...

  2. 自学_数据库<三>

    数据库 数据库概述 DBMS(DataBase Management System,数据库管理系统)和数据库.平时谈到"数据库"可能有两种含义:MSSQLServer.Oracle ...

  3. .NET常见面试题

    面试题 1  什么是 CTS.CLS 和CLR 公共语言运行库(CLR)是一个CLI 的一个实现,包含了.NET 运行引擎和符合 CLI 的类库. 通用类型系统(CTS)包含在微软公司提交的 CLI ...

  4. SQL数据库相关

    数据库相关知识点 SQL, 对表的理解, 对表的主键, 外键的理解, 视图, 为什么要有视图, 视图有什么功能, 视图与表有什么区别 主键是唯一标识的一条记录,不能重复,不能为空. 表的外键是另一个表 ...

  5. DataGridView控件绑定数据源

    前言: 近期听说DataGridView控件能直接绑定数据源.而不用穿越这层那层的忍辱负重.获取数据.真是高兴的屁颠屁颠的.后来一想二狗肯定不会弄.特意写了一个笨蛋版的教程--也算记录生活.欢度端午了 ...

  6. 强类型Dataset使用事务(改进原有方法)

    以下部份转自:http://blog.csdn.net/nfbing/article/details/5803980 关于强类型Dataset的用法和好处,我就不再多说,网上关于这方面的资料很多 , ...

  7. 使用强类型DataSet增加数据并获取自动增长的ID

    使用强类型的DataSet可以方便的操作数据库:有时候我们会对表的ID设置为自动增长,并且需要在插入数据后获取新插入数据的ID,按以下方法即可达到目的: 一.     首先建立一个表,id为自动增加, ...

  8. 强类型DataSet的使用简明教程

    关于弱类型 DataSet的缺点: 无论何时从 DataSet检索值都是以Object类型返回,需要对它进行类型转换: 给其它开发者使用 时无法知道哪些列可用: 运行时才能知道所 有列名,数据绑定麻烦 ...

  9. 2强类型DataSet (2011-12-30 23:16:59)转载▼ 标签: 杂谈 分类: Asp.Net练习笔记 http://blog.sina.com.cn/s/blog_9d90c4140101214w.html

    强类型DataSet (2011-12-30 23:16:59) 转载▼ 标签: 杂谈 分类: Asp.Net练习笔记 using System; using System.Collections.G ...

随机推荐

  1. Hadoop YARN: 1/1 local-dirs are bad: /var/lib/hadoop-yarn/cache/yarn/nm-local-dir; 1/1 log-dirs are bad: /var/log/hadoop-yarn/containers hdfs硬盘90% yarn unhealthy

    1/1 local-dirs are bad: /var/lib/hadoop-yarn/cache/yarn/nm-local-dir; 1/1 log-dirs are bad: /var/log ...

  2. 剑指offer 04_替换字符串中的空格

    #include <stdio.h> void ReplaceBlank(char string[],int length){ if(string == NULL || length == ...

  3. Ajax笔记(一)

    Ajax三步骤: Asynchronous Javascript And XML 1.运用HTML和CSS实现页面,表达信息: 2.运用XMLHttpRequest和web服务器进行数据的异步交换: ...

  4. SQLiteopenhelper创建database的过程

    首先由于SQLiteOpenHelper是一个抽象类,所以我们要创建一个自己的类实现它,并实现抽象方法, public void onCreate(SQLiteDatabase db) public ...

  5. 1 ffmpeg介绍

    重点讲解解码的过程.FFmpeg可以进行X264编码.软编码效率是非常低的.即时你编VGA的话它的效率也很低.

  6. 浏览器默认标签样式总结及css初始化程序(转)

    浏览器默认标签样式总结及css初始化程序   html中的大部分的标签都有一些糟糕的样式,有的是标签天然自带的,有的是浏览器默认设置的,我们在写网页时,这些默认的样式就会时不时的跳出来捣一下乱,搞得我 ...

  7. C++中的友元

    友元函数 在类的声明中可以声明某一个函数作为该类的友元函数,然后该函数就可以访问类中的private数据成员了. demo: /* wirten by qianshou 2013/12/6 04:13 ...

  8. .NET回归 HTML----超文本标记语言(暂时无图)

    HTML用来做网页,文件拓展名改为html可以形成网页 超文本标记语言==超越了文字的范畴,除了文字还可以有图片.视频.音频.动画特效等其它内容,由标记符号<>组成的一门计算机编程语言 H ...

  9. p3203 弹飞绵羊

    传送门 分析 基本的lct操作,建一个点N表示弹飞出去的点,每次输出N的左子树的大小即可 代码 #include<iostream> #include<cstdio> #inc ...

  10. Luogu 3267 [JLOI2016/SHOI2016]侦察守卫

    以后要记得复习鸭 BZOJ 4557 大佬的博客 状态十分好想,设$f_{x, i}$表示以覆盖完$x$为根的子树后还能向上覆盖$i$层的最小代价,$g_{x, i}$表示以$x$为根的子树下深度为$ ...