asp.net+Sqlserver 通过存储过程读取数据
Sqlserver代码 创建存储过程如下:
/*根据父id获取类别总数*/
IF EXISTS (SELECT name FROM sysobjects
WHERE name = N'getsitenodeTotal' AND type = 'P')
DROP PROCEDURE getsitenodeTotal
GO
create proc getsitenodeTotal
@notecount varchar(10) output,
@ParentID varchar(10)
as
select @notecount = count(1) from siteserver_Node where ParentID=@ParentID
go
/*执行*/
DECLARE @notecount varchar(10) /*调用时必须带OUTPUT关键字 ,返回结果将存放在变量@sum中*/
EXEC getsitenodeTotal @notecount OUTPUT ,52
print @notecount /*查询项目案例中的类别*/
IF EXISTS (SELECT name FROM sysobjects
WHERE name = N'getsitenodeall' AND type = 'P')
DROP PROCEDURE getsitenodeall
GO
create proc getsitenodeall
(
@ParentID varchar(10),
@countnode varchar(10)
)
as
begin
declare @sql nvarchar(500)
set @sql = 'select top '+str(@countnode)+' NodeID,NodeName,ParentID,ImageUrl,[Content],Description
from siteserver_Node where ParentID='+str(@ParentID)
execute(@sql)
end
go
/*执行*/
EXEC getsitenodeall 52,10 /*根据类别查询案例信息*/
IF EXISTS (SELECT name FROM sysobjects
WHERE name = N'getsitecontent' AND type = 'P')
DROP PROCEDURE getsitecontent
GO
create proc getsitecontent
(
@NodeID varchar(10),
@countnode varchar(10)
)
as
begin
declare @sql nvarchar(500)
set @sql = 'select top '+ @countnode + ' ID,NodeID,Title,Summary,SettingsXML,AddUserName,AddDate,ImageUrl,Content,LinkUrl'
+' from siteserver_Content where NodeID='+@NodeID+' order by ID desc'
execute(@sql)
end
go
/*执行*/
EXEC getsitecontent 53,10 /*根据类别获取新闻总数*/
IF EXISTS (SELECT name FROM sysobjects
WHERE name = N'getsitecontentTotal' AND type = 'P')
DROP PROCEDURE getsitecontentTotal
GO
create proc getsitecontentTotal
@nodecount varchar(10) output,
@NodeID varchar(10)
as
select @nodecount = count(1) from siteserver_Content where NodeID=@NodeID
go
/*执行*/
DECLARE @nodecount varchar(10) /*调用时必须带OUTPUT关键字 ,返回结果将存放在变量@sum中*/
EXEC getsitecontentTotal @nodecount OUTPUT ,53
print @nodecount /*根据id查询单条项目案例信息*/
IF EXISTS (SELECT name FROM sysobjects
WHERE name = N'getsitecontentById' AND type = 'P')
DROP PROCEDURE getsitecontentById
GO
create proc getsitecontentById
(
@ID varchar(10)
)
as
begin
declare @sql nvarchar(500)
set @sql = 'select ID,NodeID,Title,Summary,SettingsXML,AddUserName,AddDate,ImageUrl,Content,LinkUrl from siteserver_Content where ID='+@ID
execute(@sql)
end
go
/*执行*/
EXEC getsitecontentById 240
存储过程
.net中返回json数据
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;
using Newtonsoft.Json;
using System.Web.Script.Serialization; /// <summary>
///WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService { public WebService () { //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
public string HelloWorld() {
return "Hello World";
} [WebMethod(Description = "根据父id获取类别总数")]
public void getsitenodeTotal(string ParentID)
{
HttpContext.Current.Response.ContentType = "application/json;charset=utf-8";
string jsonCallBackFunName = string.Empty;
//jsonCallBackFunName = HttpContext.Current.Request.Params["jsoncallback"].ToString();
string jsonStr = string.Empty;
//@notecount
SqlParameter[] para ={
new SqlParameter("@notecount",SqlDbType.VarChar),
new SqlParameter("@ParentID", ParentID)
};
para[].Value = -;
para[].Direction = ParameterDirection.Output;
SQLHelper.ExecuteScalar("getsitenodeTotal", CommandType.StoredProcedure, para);
string result = para[].Value.ToString();
jsonStr = JsonConvert.SerializeObject(result); HttpContext.Current.Response.Write(string.Format("{0}({1})", jsonCallBackFunName, new JavaScriptSerializer().Serialize(jsonStr)));
} [WebMethod(Description = "查询项目案例中的类别")]
public void getsitenodeall(string ParentID, string countnode)
{
HttpContext.Current.Response.ContentType = "application/json;charset=utf-8";
string jsonCallBackFunName = string.Empty;
//jsonCallBackFunName = HttpContext.Current.Request.Params["jsoncallback"].ToString();
string jsonStr = string.Empty;
List<siteserver_Node> sitenodes = new List<siteserver_Node>();
SqlParameter[] para = {
new SqlParameter("@ParentID", ParentID),
new SqlParameter("@countnode", countnode)
};
using (SqlDataReader dr = SQLHelper.ExecuteReader("getsitenodeall", CommandType.StoredProcedure, para))
{
while (dr.Read())
{
siteserver_Node sitenode = new siteserver_Node(
Convert.ToInt32(dr["NodeID"]),
dr["NodeName"].ToString(),
Convert.ToInt32(dr["ParentID"]),
dr["ImageUrl"].ToString(),
dr["Content"].ToString(),
dr["Description"].ToString()
);
sitenodes.Add(sitenode);
}
}
jsonStr = JsonConvert.SerializeObject(sitenodes);
HttpContext.Current.Response.Write(string.Format("{0}({1})", jsonCallBackFunName, new JavaScriptSerializer().Serialize(jsonStr)));
} [WebMethod(Description = "根据类别查询案例信息")]
public void getsitecontent(string NodeID, string countnode)
{
HttpContext.Current.Response.ContentType = "application/json;charset=utf-8";
string jsonCallBackFunName = string.Empty;
//jsonCallBackFunName = HttpContext.Current.Request.Params["jsoncallback"].ToString();
string jsonStr = string.Empty;
List<siteserver_Content> sitecontents = new List<siteserver_Content>();
SqlParameter[] para = {
new SqlParameter("@NodeID", NodeID),
new SqlParameter("@countnode", countnode)
};
using (SqlDataReader dr = SQLHelper.ExecuteReader("getsitecontent", CommandType.StoredProcedure, para))
{
while (dr.Read())
{
siteserver_Content sitecontent = new siteserver_Content(
Convert.ToInt32(dr["ID"]),
Convert.ToInt32(dr["NodeID"]),
dr["Title"].ToString(),
dr["Summary"].ToString(),
dr["SettingsXML"].ToString(),
dr["AddUserName"].ToString(),
dr["AddDate"].ToString(),
dr["ImageUrl"].ToString(),
dr["Content"].ToString(),
dr["LinkUrl"].ToString()
);
sitecontents.Add(sitecontent);
}
}
jsonStr = JsonConvert.SerializeObject(sitecontents);
HttpContext.Current.Response.Write(string.Format("{0}({1})", jsonCallBackFunName, new JavaScriptSerializer().Serialize(jsonStr)));
} [WebMethod(Description = "根据类别获取新闻总数")]
public void getsitecontentTotal(string NodeID)
{
HttpContext.Current.Response.ContentType = "application/json;charset=utf-8";
string jsonCallBackFunName = string.Empty;
//jsonCallBackFunName = HttpContext.Current.Request.Params["jsoncallback"].ToString();
string jsonStr = string.Empty;
SqlParameter para =new SqlParameter("@NodeID", NodeID);
string sql = "select count(1) from siteserver_Content where NodeID=@NodeID";
string result =SQLHelper.ExecuteScalar(sql, CommandType.Text, para).ToString();
jsonStr = JsonConvert.SerializeObject(result);
HttpContext.Current.Response.Write(string.Format("{0}({1})", jsonCallBackFunName, new JavaScriptSerializer().Serialize(jsonStr)));
} [WebMethod(Description = "根据id查询单条项目案例信息")]
public void getsitecontentById(string ID)
{
HttpContext.Current.Response.ContentType = "application/json;charset=utf-8";
string jsonCallBackFunName = string.Empty;
//jsonCallBackFunName = HttpContext.Current.Request.Params["jsoncallback"].ToString();
string jsonStr = string.Empty;
siteserver_Content sitecontent = new siteserver_Content();
SqlParameter para = new SqlParameter("@ID", ID);
using (SqlDataReader dr = SQLHelper.ExecuteReader("getsitecontentById", CommandType.StoredProcedure, para))
{
while (dr.Read())
{
sitecontent = new siteserver_Content(
Convert.ToInt32(dr["ID"]),
Convert.ToInt32(dr["NodeID"]),
dr["Title"].ToString(),
dr["Summary"].ToString(),
dr["SettingsXML"].ToString(),
dr["AddUserName"].ToString(),
dr["AddDate"].ToString(),
dr["ImageUrl"].ToString(),
dr["Content"].ToString(),
dr["LinkUrl"].ToString()
);
break;
}
}
jsonStr = JsonConvert.SerializeObject(sitecontent);
HttpContext.Current.Response.Write(string.Format("{0}({1})", jsonCallBackFunName, new JavaScriptSerializer().Serialize(jsonStr)));
}
}
asp.net+Sqlserver 通过存储过程读取数据的更多相关文章
- asp.net C#操作存储过程读取存储过程输出参数值
这段时间在做一个价格平台的项目时候,同事让我写一个存储过程.该存储过程是根据查询条件得出一组新数据,并且返回该组数据的总条数,此处的存储过程我用到了分页,其中主要知识点和难点是之前做项目的时候没有用到 ...
- 用kettle从mysql中使用存储过程读取数据写入到sqlserver数据库
1.mysql存储过程,可以实现动态表读取,满足较为复杂的业务逻辑 DROP PROCEDURE if exists p_get_car_trace; delimiter // CREATE PROC ...
- ASP.NET&AJAX&JSON - 动态读取数据
因为之前帮WM组做了一个delivery的dashboard,大概用了3周的时间,.net也忘了差不多了,ajax和highchart表也是现学的,蛮费劲!总算也搞出来了.发帖纪录一下. 1. 前台A ...
- Asp.net导入Excel并读取数据
protected void Button1_Click(object sender, EventArgs e) { if (station.HasFile == false)//HasFile用来检 ...
- sqlserver从xlsx读取数据
exec sp_configure 'show advanced options',1 reconfigure exec sp_configure 'Ad Hoc Distributed Querie ...
- ASP.NET MVC + EF 利用存储过程读取大数据,1亿数据测试很OK
看到本文的标题,相信你会忍不住进来看看! 没错,本文要讲的就是这个重量级的东西,这个不仅仅支持单表查询,更能支持连接查询, 加入一个表10W数据,另一个表也是10万数据,当你用linq建立一个连接查询 ...
- ASP.NET MVC + EF 利用存储过程读取大数据
ASP.NET MVC + EF 利用存储过程读取大数据,1亿数据测试很OK 看到本文的标题,相信你会忍不住进来看看! 没错,本文要讲的就是这个重量级的东西,这个不仅仅支持单表查询,更能支持连接查询, ...
- [MVC4]ASP.NET MVC4+EF5(Lambda/Linq)读取数据
继续上一节初始ASP.NET MVC4,继续深入学习,感受了一下微软的MVC4+EF5(EntityFramework5)框架的强大,能够高效的开发出网站应用开发系统,下面就看一下如何用MVC4+EF ...
- [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:为ASP.NET MVC应用程序读取相关数据
这是微软官方教程Getting Started with Entity Framework 6 Code First using MVC 5 系列的翻译,这里是第七篇:为ASP.NET MVC应用程序 ...
随机推荐
- gulpfile的结构
使用了 yargs 用于获取启动参数,针对不同参数,切换任务执行过程时需要,本项目中的useCache和useSess path 不明,貌似是用来将某个目录中的文件 ...
- wamp环境网站根目录更改
1.修改wampserver的默认目录 安装好wampserver后,网站根目录默认为:安装目录\wamp\www,也就是wampserver安装目录下的www文件夹. 我们以更改为:D\www为例. ...
- thinkphp 内置函数详解
D() 加载Model类M() 加载Model类 A() 加载Action类L() 获取语言定义C() 获取配置值 用法就是 C("这里填写在配置文件里数组的下标")S( ...
- D题(贪心)
D - D Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descripti ...
- uva 10382 - Watering Grass(区域覆盖问题)
Sample Input 8 20 2 5 3 4 1 1 2 7 2 10 2 13 3 16 2 19 4 3 10 1 3 5 9 3 6 1 3 10 1 5 3 1 1 9 1 Sample ...
- json-lib 使用教程
//关于java map与JSONObject类互相转换 Map<String,Object> map=new HashMap<String,Object>(); map.pu ...
- PIL Image 转成 wx.Image、wx.Bitmap
import wx from PIL import Image def ConvertToWxImage(): pilImage = Image.open('1.png') image = wx.Em ...
- 在CentOS6上使用YUM安装php5.5.x
这里使用 Webtatic EL6的YUM源来安装php5.5,我们首页安装Webtatic EL6 YUM源 rpm -Uvh http://repo.webtatic.com/yum/el6/la ...
- 至芯FPGA培训中心-1天FPGA设计集训(赠送FPGA开发板)
至芯FPGA培训中心-1天FPGA设计集训(赠送开发板) 开课时间2014年5月3日 课程介绍 FPGA设计初级培训班是针对于FPGA设计技术初学者的课程.课程不仅是对FPGA结构资源和设计流程的描述 ...
- XML SAX解析
SAX是一种占用内存少且解析速度快的解析器,它采用的是事件驱动,它不需要解析完整个文档,而是按照内容顺序,看文档某个部分是否符合xml语法,如果符合就触发相应的事件.所谓的事件就是些回调方法( cal ...