存储过程的调用!

本文详细介绍了如何使用C#连接SQL Server数据库并调用存储过程,包括参数设置、登录验证及错误处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  

存储过程的调用!

 

 

           string x = @"server=HP-PC\SQLEXPRESS;IntegratedSecurity=true;Initial            Catalog=bydticket";

           SqlConnection scon = new SqlConnection(x);

           SqlCommand scmm = new SqlCommand();

           scmm.CommandText = "mylogin3";

           scmm.CommandType = System.Data.CommandType.StoredProcedure;

           scmm.Connection = scon;

 

 

 

           SqlParameter param = new SqlParameter();

           param.SqlDbType = System.Data.SqlDbType.NVarChar;

           param.Size = 8;

           param.ParameterName = "@username";

 

           param.Value = this.txtuser.Text;

           scmm.Parameters.Add(param);

 

           param = new SqlParameter("@password",System.Data.SqlDbType.VarChar, 16);

           param.Direction = System.Data.ParameterDirection.Output;

           scmm.Parameters.Add(param);

           scon.Open();

           scmm.ExecuteNonQuery();

           string mima=scmm.Parameters["@password"].Value.ToString();

        

 

         

            if (this.txtuser.Text == "" || this.txtpassword.Text =="")

           {

                Response.Write("请输入用户名/密码!");

 

           }

            else if (this.txtpassword.Text == mima)

           {

           

                Response.Write("登陆成功!");

           }

           else

           {

                 Response.Write("用户名/密码错误!");

              

               

 

           }

           scon.Close();

           

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值