日期:2014-05-17 浏览次数:20495 次
if (exists (select * from sys.objects where name = 'Query_Login')) drop proc Query_Login go create proc Query_Login ( @name nvarchar(20), @password nvarchar(20), @isAvailable varchar(5) out, @num int out ) as select @num=COUNT(*) from Users u,[login] l where u.name = @name and l.[passWord] = @password and u.id=l.userID; select @isAvailable = IsAvailable from [login] where userID = (select id from Users where name = @name) --print @name+' '+@password go
public int DeleteMX(string X1,string X2,out string X3, out string strMsg) { SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.nvarchar,20), new SqlParameter("@password", SqlDbType.nvarchar,20), new SqlParameter("@isAvailable", SqlDbType.varchar,5), new SqlParameter("@num", SqlDbType.Int) }; parameters[0].Value = X1; parameters[1].Value = X2; parameters[2].Direction = ParameterDirection.Output; parameters[3].Direction = ParameterDirection.Output; int flag; flag = DbHelperSQL.RunProcedureTran("Query_Login", parameters);//调用存储过程 X3 = Convert.ToString(parameters[2].Value);//获取返回的参数isAvailable strMsg = Convert.ToString(parameters[3].Value);//获取返回的参数num return flag; }
------解决方案--------------------
4楼已经给你写了例子了。
返回来的不再是sql语句是数据
strMsg = Convert.ToString(parameters[3].Value);//获取返回的参数num
------解决方案--------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[存储过程名]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
这个才是判断存储过程是否存在,你那是个bug
out 是地址引用, string X3 , string Msg的会随着处理改变,你传入的就是要输出的。
------解决方案--------------------
就是判断当前登录用户是否有效,返回是否有效值,以及条数