首页 新闻 会员 周边 捐助

有关存储过程

0
悬赏园豆:5 [已关闭问题] 关闭于 2008-11-09 12:14

我做了一个登录框    使用存储过程proc_select_table   不知杀原因   存储过程没起作用    

 CREATE proc proc_login_select
@login_name varchar (20)=null,
@login_pwd varchar (15)=null,
@ReturnInfo nvarchar(50)=null output
as
begin
   if exists(select login_name from tb_login where login_name=@login_name and login_pwd=@login_pwd)
 select @ReturnInfo=login_power from tb_login where login_name=@login_name
    else
 set @ReturnInfo='none'
end
GO

 


下面是ClsLoginmothed.cs      存储过程就是在这里使用的

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

namespace xsgl.mothedCls
{
   
    class ClsLoginmothed
    {
        ClsCon con = new ClsCon();
        SqlCommand sqlCommand;
        public string select_table(ClsLogin cf)
        {
            try
            {
                con.conDataBase();
                 sqlCommand = new SqlCommand("proc_login_select", con.conn);
                 sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Connection.Open();
                //con.conn.Open();
                SqlParameter[] prams =
                    {
                        new SqlParameter("@login_name",SqlDbType .VarChar ,50),
                        new SqlParameter ("@login_pwd",SqlDbType .VarChar ,50),
                        new SqlParameter ("@ResultInfo",SqlDbType .VarChar ,50,ParameterDirection.Output ,true ,0,0,string.Empty ,DataRowVersion .Default ,null )
                    };
                prams[0].Value = cf.LName;
                prams[1].Value = cf.LPwd;
                foreach (SqlParameter parameter in prams)
                {
                    sqlCommand.Parameters.Add(parameter);
                }
                sqlCommand.ExecuteNonQuery();
                string strResult = sqlCommand.Parameters["ResultInfo"].Value.ToString();
                con.closeCon();
                return strResult;
            }
            catch(Exception ey)
            {
                con.closeCon();
                return ey.Message.ToString();
            }
       
        }
    }
}

下面是FrmUserLogin.cs              
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using xsgl.mothedCls;

namespace xsgl
{
    public partial class FrmUserLogin : Form
    {
        ClsCon con = new ClsCon();
        ClsLogin cl = new ClsLogin();
        ClsLoginmothed cm = new ClsLoginmothed();
        string errornum = string.Empty;
        int num = 0;
        public FrmUserLogin()
        {
            InitializeComponent();
        }

        private void FrmUsertb_login_Load(object sender, EventArgs e)
        {
            con.conDataBase();
            SqlDataAdapter da = new SqlDataAdapter("select * from tb_login", con.conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            this.comboBox1.DataSource = dt.DefaultView;
            comboBox1.DisplayMember = "login_name";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            cl.LName = this.comboBox1.Text;
            cl.LPwd = this.textBox1.Text.Trim().ToString();
            string power = cm.select_table(cl);

            if (power!="none")
            {
                FrmMain fm = new FrmMain();
                this.Hide();
              //  fm.M_str_power = this.comboBox1.Text + "@" + power;
                fm.Show();
            }
            else if(this.textBox1.Text=="" && this.comboBox1.Text =="")
            {
                FrmMain fm = new FrmMain();
                this.Hide();
                fm.Show();
            }
            else
            {

                if (errornum == cl.LName )
                {
                    num += 1;

                    if (num >= 3)
                        this.Close();

                }
                else
                {
                    errornum = cl.LName ;
                    num += 1;
                }

                MessageBox.Show("密码有误,你有三次机会,这是第" + num + "次");
            }
        }
    大哥们帮我看下

阿乐的主页 阿乐 | 初学一级 | 园豆:105
提问于:2008-11-02 13:16
< >
分享
所有回答(1)
0

 return strResult;//此处返回“none”或者正确的结果(一个字符串)
  }
  catch(Exception ey)
  {
  con.closeCon();
  return ey.Message.ToString(); //返回的也是一个字符串
  }

那么你在调用的时候,可以区分是返回了正确的结果还是发生了异常了吗?

上不了岸的鱼 | 园豆:4613 (老鸟四级) | 2008-11-02 14:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册