首页 > 新闻系统 > 编程天地 > 文章正文

C#中调用SQL存储过程实现登录认证代码

2008-05-05 08:53:00 来源:中国自学编程网 作者:佚名 点击:

存储过程如下:

set ANSI_NULLS ONset QUOTED_IDENTIFIER ONGOALTER

procedure [dbo].[security_check](@user_sort int,@userID nchar(16),@userPWD nchar(16) )

as

declare @uid nchar(16);

declare @pwd nchar(16);

declare @state bit;

set @state=0;

if( @user_sort=1) 

begin  

     declare  cursor_temp cursor local for   --定义游标

               select 学号,密码   from 学生表  where 学号 = @userID and 密码 = @userPWD;   

     open cursor_temp;      --打开游标

      fetch cursor_temp into @uid,@pwd;    --推进游标

      close cursor_temp;                   --关闭游标

 end

if( @uid =@userID and @pwd=@userPWD ) 

        begin 

                set @state=1;  

                return @state; 

        end;

else 

        begin 

        set @state=0; 

        return @state; 

end;                  

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

C#代码如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace 密码验证
{
    class security
    {
        public static DataSet  check(string uid)
        {
            SqlConnection mySqlConnection = new SqlConnection("server=.\\SqlExpress;database=XSXK;integrated security=SSPI");

            mySqlConnection.Open();

            SqlCommand mySqlCommand = mySqlConnection.CreateCommand();

            mySqlCommand.CommandText = "select * from 学生表 where 学号 =" + uid;

            SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();

            DataSet myDataSet = new DataSet() ;

       &

9 7 3 1 2 3 4 4 8 :

相关文章:

    无相关新闻
    无相关新闻

精彩推荐
焦点大图推荐
本类热门文章

论坛美图

广告联系 | 版权说明 | 意见建议 | 加入收藏 | 军网站群 [ 军软件园 - 军软件商城 - 军软件园论坛 ]

电信与信息服务业务经营许可证:京ICP证050203