ASP.NET 中调用存储过程
用ASP.NET与SQL SERVER可是缘份最好了,稍大的程序一般第一先考虑的是SQL SERVER,只是一些很考虑经济的才使用ACCESS等了。用SQL SERVER,为了使数据库的效率更好,一般都会才取存储过程,因存储过程执行速度快,并且可以实现一些高级的查询等功能。比如传入一些数据参数,但执行的SQL过程可能不同等。
下面就来个例子,建立一新的角色,要求角色的名字不能重复,以下是一存储过程。
CREATE PROCEDURE sp_AccountRole_Create@CategoryID int,
@RoleName nvarchar(10),
@Description nvarchar(50),
@RoleID int output
AS
DECLARE @Count int -- 查找是否有相同名称的记录
SELECT @Count = Count(RoleID) from Account_Role WHERE
RoleName = @RoleName IF @Count = 0 INSERT INTO Account_Role
(CategoryID, RoleName, Description) valueS
(@CategoryID, @RoleName, @Description) SET @RoleID = @@IDENTITY RETURN 1
GO
执行存储过程的C#过程:
SqlConnection DbConnection = new SqlConnection(mConnectionString);
SqlCommand command = new SqlCommand( "sp_AccountRole_Create", DbConnection );
DbConnection.Open(connectString);
// 废置SqlCommand的属性为存储过程
command.CommandType = CommandType.StoredProcedure;command.Parameters.Add("@CategoryID", SqlDbType.Int, 4);
command.Parameters.Add("@RoleName", SqlDbType.NVarChar, 10);
command.Parameters.Add("@Description", SqlDbType.NVarChar, 50);
command.Parameters.Add("@RoleID", SqlDbType.Int, 4);
// 返回值
command.Parameters.Add("Returnvalue",
SqlDbType.Int,
4, // Size
ParameterDirection.Returnvalue,
false, // is nullable
0, // byte precision
0, // byte scale
string.Empty,
DataRowVersion.Default,
null );command.parameters["@CategoryID"].value = permission.CategoryID;
command.parameters["@RoleName"].value = permission.PermissionName;
command.parameters["@Description"].value = permission.Description;
// 可以返回新的ID值
command.parameters["@Ro
相关文档:
这段时间,老大在看了网站后,发现viewstate所产生的一堆乱码,严重影响了我们网站http://www.xbcar.net 西部汽车网的打开速度和搜索引擎的抓取.就给我下了道铁令,三天内必须解决.这下该轮到我头大了,
例如:
input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="dEV4cHJlc3Npb247UmVhZE9ub ......
HTML代码:
<script language="javascript" event="onclick" for="ImageButton1">
return confirm('确定要保存变更吗?');//返回false时不执行ImageButton1_Click方法,返回ture时执行ImageButton1_Click方法
</script>
<asp:ImageButton ID="ImageButton1" runat="server" ImageAlig ......
using System.Text.RegularExpressions;
Regex reg = new Regex(@"^\d+$"); //验证字符串
Response.Write( reg.IsMatch(""));
Response.Write(reg.IsMatch("sf"));
Response.Write ......
ASP.NET获取天气预报大致分析有 1到某个网站上分析网站的代码获取;2自己写驱动服务和web服务 第二种水太深不曾涉及。
ASP.NET后台程序获取中央气象台天气预报
1.天气封装成一个实体
2.可以获取当天天气,也可以获取未来五天的天气集合
using System;
using System.Collections.Generic;
using System.Text;
......
1. 虽然是.net,但是已经几乎完全放弃了服务器控件,取而代之的是html控件,赋值时候可以通过注册javascript脚本来完成。只是学习途中的一个实践,不知道这样会不会减少编译,增加运行效率。
2. 推荐跟JQuery结合,NND,这丫真的很强大...如果你跟我一样是js小白,又想NB一把弄个AJAX什么的,用JQuery把。。。这孩子包你满 ......