当前位置:首页 > 资讯 > info6 > 正文

SQL output用法学习心得

发表于: 2010-01-20 ? 作者:chduguxue ? 来源:转载 ? 浏览:
摘要: ALTERPROCEDUREdbo.Login@AdminNamenvarchar(50)=null,@AdminPasswordnvarchar(50)=null,@LoginStateintoutputASifexists(SELECT*FROM[Admin]WHEREAdminName=@AdminNameandAdminPassword=@AdminPasswordandState='1'

ALTER PROCEDURE dbo.Login @AdminName nvarchar(50)=null, @AdminPassword nvarchar(50)=null, @LoginState int output AS if exists (SELECT * FROM [Admin] WHERE AdminName=@AdminName and AdminPassword=@AdminPassword and State='1')--这个State是用来表示该用户是否被禁用 set @LoginState=1 --登录成功 else set @LoginState=0 --登录失败

?

string connStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString; SqlConnection con = new SqlConnection(connStr); con.Open(); SqlCommand thisCommand = new SqlCommand("Login", con); thisCommand.CommandType = CommandType.StoredProcedure; thisCommand.Parameters.Add("@AdminName", SqlDbType.NVarChar, 50).Value =AdminNameText.Text.Trim(); thisCommand.Parameters.Add("@AdminPassword", SqlDbType.Char, 200).Value = PasswordText.Text.Trim(); thisCommand.Parameters.Add("@LoginState", SqlDbType.Int); thisCommand.Parameters["@LoginState"].Direction = ParameterDirection.Output; thisCommand.ExecuteNonQuery(); Object objTempRole = thisCommand.Parameters["@LoginState"].Value; LoginLabel.Text = objTempRole.ToString();

SQL output用法学习心得

版权所有 IT知识库 CopyRight ? 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号