asp中實現sql事務登入 增刪改查

2021-06-10 23:03:09 字數 3059 閱讀 8078

web.config

<?xml version="1.0" encoding="utf-8"?>

login.aspx:

<%@ page language="c#" autoeventwireup="true" codebehind="login.aspx.cs" inherits="webado.login" %>

login.aspx.cs:

using system;

using system.collections.generic;

using system.linq;

using system.web;

using system.web.ui;

using system.web.ui.webcontrols;

using system.data.sqlclient;

using system.configuration;

using system.data;

namespace webado

else}}

}protected void button2_click(object sender, eventargs e)

else}}

}protected void button3_click(object sender, eventargs e)

else}}

}protected void button4_click(object sender, eventargs e)

else}}

}protected void button5_click(object sender, eventargs e)}}

}}sql:

--1 儲存過程復用**案例——如果english不及格的人超過半數,則給每個人增加2分,迴圈加,直到不及格的人數少於一半。

--usp_promotegrade有乙個引數,及格分數線@passline。

select * from score

create proc usp_promotegrade @a int

asbegin

declare @a1 int

set @a1=(select count(*) from score where english<@a)

while(@a1>(select count(*) from score)/2)

begin

update score set english=english+2

set @a1=(select count(*) from score where english<@a)

endend

exec usp_promotegrade 60

--2ado中使用儲存過程

--1-1寫usp_login儲存過程,引數有三個,其中第三個引數為output,用來返回登陸是否成功,

--成功1,失敗0( @uname varchar(50),  @password varchar(50),  @result bit output)

use test1

create proc usp_login @uname varchar(50),@password varchar(50),@result bit output

asbegin

declare @t_count int

set @t_count= (select count(*) from t_denglu where f_user=@uname and f_password=@password)

if(@t_count>0)

begin

set @result=1

endelse

begin

set @result=0

endend

------------------------------

create proc usp_chklogin @uname varchar(50),@password varchar(50)

asbegin

select count(*) from t_denglu where f_user=@uname and f_password=@password

end----------------------------------

create proc usp_insert @uname varchar(50),@password varchar(50),@message int output

asbegin

declare @fcount int

set @fcount=(select count(*) from t_denglu where f_user=@uname)

if(@fcount>0)

begin

set @message=0;

endelse

begin

set @message=1;

insert into t_denglu (f_user,f_password) values (@uname,@password);

endend

--------------------------------

create proc usp_delect @name varchar(50),@message bit output

asbegin

declare @fcount int=(select count(*) from t_denglu where f_user=@name)

if(@fcount>0)

begin

set @message=1;

delete from t_denglu where f_user=@name

endelse

begin

set @message=0;

endend

------------------------------

create proc usp_select @name varchar(50)

asbegin

select * from t_denglu where f_user=@name;

end

ASP中資料的增 刪 改 查

ms sql鏈結資料庫配置語句 dim dbtype dbtype mssql dim strconn strconn driver server local uid sa pwd database 資料庫名 dim db set db server.createobject adodb.conne...

SQL中的事務

sql中的事務 事務 begin transaction 開始事務 commit transaction 提交事務 rollboack transaction 回滾事務 set implicit ransaction on 隱式事務 update customer set nickname nick...

SQL中事務隔離

use db3 insert into account name,balance values 張三 1000 李四 1000 張三轉500給李四 張三賬戶減500,李四加500,需要確保這些動作同時完成,不然會有損失 update account set balance 5000 1.張三轉賬50...