存储过程

GO
create proc [dbo].[userLauncher](@Phone varchar(13),@Passwork varchar(24))  --创建存储过程,参数@Phone,@Passwork
as
begin
    declare @status int  --声明游标
    if exists(select * from[JXLing].[dbo].[UserInformation] where [userPhone]= @Phone and userPasswork = @Passwork)   --判断用户名和密码是否存在
    begin
    insert into JXLing.dbo.UserLaunch ([userPhone],[launchTime]) values (@Phone,GETDATE())
     if @@ERROR <> 0 --判断是否发生异常
     set @status = 0; --赋值
     else
     set @status = 1;
    end
    else
    begin
    set @status = -1;
    end
    return @status;

end


GO
ALTER proc [dbo].[userLauncher](@Phone varchar(13),@Passwork varchar(24))  --修改存储过程
as
begin
    declare @status int  --声明游标
    if exists(select * from[JXLing].[dbo].[UserInformation] where [userPhone]= @Phone and userPasswork = @Passwork)   --判断用户名和密码是否存在
    begin
    insert into JXLing.dbo.UserLaunch ([userPhone],[launchTime]) values (@Phone,GETDATE())
     if @@ERROR <> 0 --判断是否发生异常
     set @status = 0; --赋值
     else
    select top 1 @status= id from [ProductInformation] where id = @@IDENTITY
    end
    else
    begin
   select top 1 @status= id from [ProductInformation] where id = @@IDENTITY
    end
    return @status
end
 
 declare @a int
 select top 1 @a= id from [ProductInformation] where id = @@IDENTITY

 go

exec userLauncher '1234567','1234567'   --执行存储过程 return 需要游标接收,展示




C#调用存储过程

 /// <summary>
        /// 用户登陆存储过程  2017-03-27 17:28:21 linganyong
        /// </summary>
        /// <param name="userPhone"></param>
        /// <param name="userPasswork"></param>
        /// <returns></returns>
        public SqlCommand userLauncher(UserInformation model) {

           //  localhost -- 链接地址 sa用户名

             string connectionString = "Initial Catalog=JX900;Data Source=localhost;User ID=sa;Password=123456;Integrated Security=True";
             SqlConnection sqlConnection = new SqlConnection(connectionString);
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.Connection = sqlConnection;
            sqlConnection.Open();

            #region 用户登陆存储过程
            SqlCommand com = new SqlCommand("userLauncher",sqlConnection);   //存储过程名称
            com.CommandType = CommandType.StoredProcedure;
            com.Parameters.AddWithValue("@phone", model.UserPhone);  //参数
            com.Parameters.AddWithValue("@passwork", model.UserPasswork);  //参数
            SqlParameter parReturn = new SqlParameter("@status",SqlDbType.Int);   //返回
            parReturn.Direction = ParameterDirection.ReturnValue;
            com.Parameters.Add(parReturn);
            com.ExecuteNonQuery();
            return com;
            #endregion

        }

       获取存储过程的返回值 : int result = (int)cmd.Parameters["@status"].Value;

    


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值