操作C# Dataset介绍

开发 后端
本文介绍操作C# Dataset,在AJAX 开发中,需要调用业务函数,操作C# Dataset,读取数据集,具体操作方法如下。

最近在AJAX 开发中,需要调用业务函数,操作C# Dataset,读取数据集,具体操作方法如下:

新建一 WEB 项目,创建一业务类:操作C# Dataset代码如下所示:

using System;  
using System.Data;  
using System.Configuration;  
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.OleDb;  
using System.Text;  
 
/**//// <summary> 
/// test 的摘要说明  
/// </summary> 
public class test  
{  
public test()  
{  
//  
// TODO: 在此处添加构造函数逻辑  
//  
}  
 
// 数据集传递测试  
[Ajax.AjaxMethod()]  
public DataSet GetDataSet()  
{  
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=D:工作项目分析 estdb.mdb;Persist Security Info=True;");  
DataSet ds = new DataSet();  
try  
{  
OleDbCommand cmd = conn.CreateCommand();  
cmd.CommandText = "select * from t_name";  
cmd.CommandType = CommandType.Text;  
 
OleDbDataAdapter da = new OleDbDataAdapter(cmd);  
da.Fill(ds);  
return ds;  
}  
catch  
{  
conn.Close();  
throw;  
}  
}  
}创建好业务类以后,再新建一 Aspx 页面,在页面的 Page_Load 中注册业务类: 
protected void Page_Load(object sender, EventArgs e)  
{   Ajax.Utility.RegisterTypeForAjax(typeof(test));   }页面代码如下: <%@ Page Language="C#" AutoEventWireup="true" 
CodeFile="read_dataset.aspx.cs" Inherits="read_dataset" %>    <!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>read_dataset</title>    <script language="JavaScript">    function getDataSet()   {   var ds =test.GetDataSet().value;   if(ds != null && typeof(ds) == "object" && ds.Tables != null)   {   var s = new Array();   s[s.length] = "<table style='border: #000000 1px solid; color: #993333;  font-family: 'Microsoft Sans Serif'; background-color: #ffff99;'>";     for(var i=0; i<ds.Tables[0].Rows.length; i++)   {   s[s.length] = "<tr>";   s[s.length] = "<td>" + ds.Tables[0].Rows[i].id + "</td>";   s[s.length] = "<td>" + ds.Tables[0].Rows[i].f_date + "</td>";   s[s.length] = "<td>" + ds.Tables[0].Rows[i].f_name + "</td>";   s[s.length] = "</tr>";   }     s[s.length] = "</table>";   document.getElementById("div1").innerHTML = s.join("");   }   else   {   alert("调用Ajax接口函数错误!");   }   }   </script>    </head>  <body>  <form id="form1" runat="server">  <input type="button" value="dataset" onclick="getDataSet();" />  <div id="div1">  </div>  </form>  </body>  </html> 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.

以上介绍操作C# Dataset

【编辑推荐】

  1. 概述C#实现文件下载
  2. C#搞定网站验证码的方法
  3. 浅谈C# String对象
  4. C#命名空间学习笔记
  5. 浅析C#调用ActiveX控件
责任编辑:佚名 来源: IT168
相关推荐

2009-08-25 17:28:23

C#创建DataSet

2009-08-03 17:12:40

C#指针操作

2009-08-12 18:35:36

C# ArrayLis

2009-07-31 14:15:38

C# 构造函数

2009-08-04 08:48:44

C#内置特性

2009-08-12 09:41:28

C# Director

2009-08-18 16:45:40

C# Raw Sock

2009-09-03 15:57:11

C# SystemMe

2009-08-12 15:34:40

C# DBNull

2009-08-25 10:24:29

C# delegate

2009-08-17 16:47:51

C# Anonymou

2009-08-10 16:30:56

C# BitmapDa

2009-09-02 17:20:50

C# Parsing

2009-08-21 17:55:52

C#复合控件

2009-08-24 15:41:50

C#连接SQL Ser

2009-09-03 17:21:51

C# VSProjec

2009-09-03 16:51:27

C#类属性

2009-09-01 10:20:28

C#多种语句

2009-08-10 16:19:37

C#冒泡排序

2009-08-14 17:27:56

C#方法参数
点赞
收藏

51CTO技术栈公众号