我写了一个存储过程,带了三个参数,可以传一个也可以是两个,或三个,但我的存储过程在程序中执行后没数据啊,如果单独拿出来执行是成功的。请大侠们帮帮忙,小弟急用!

解决方案 »

  1.   

    把你存储过程copy出来看看啊
      

  2.   

    在程序里是怎么执行的?
    不同的数据返回方式要用不同的方式执行。
    参数返回,执行后要处理传出参数的值。
    结果集返回,要用ExcuteReader或者ExcuteScaler等方式执行并获取数据。
      

  3.   

    我用的是DataSet,返回的总是空的啊
      

  4.   

    存储过程是
    CREATE Procedure Up_Bap_GetAddressBook
    (
    @EmployeeID varchar(20)='a',
    @employeesName varchar(10)='b',
    @employeesSex varchar(2)='c'
    )
    AS
    if(@EmployeeID != 'a' and @employeesName != 'b' and @employeesSex != 'c')
    SELECT employeesID,employeesName,employeesSex,employeesPhone,employeesEmail,employeesAddress
     from EmployeesInfo where employeesID='%'+@EmployeeID+'%' and employeesName='%'+@employeesName+'%' and employeesSex=@employeesSex
     else if(@EmployeeID = 'a' and @employeesName!='b' and @employeesSex!='c')
     SELECT employeesID,employeesName,employeesSex,employeesPhone,employeesEmail,employeesAddress
     from EmployeesInfo where employeesName='%'+@employeesName+'%' and employeesSex=@employeesSex
     if(@EmployeeID!='a' and @employeesName = 'b' and @employeesSex!='c')
    SELECT employeesID,employeesName,employeesSex,employeesPhone,employeesEmail,employeesAddress
     from EmployeesInfo where employeesID='%'+@EmployeeID+'%' and employeesSex=@employeesSex
    if(@EmployeeID!='a' and @employeesName!= 'b' and @employeesSex = 'c')
    SELECT employeesID,employeesName,employeesSex,employeesPhone,employeesEmail,employeesAddress
     from EmployeesInfo where employeesID='%'+@EmployeeID+'%' and employeesName='%'+@employeesName+'%'
    if(@EmployeeID = 'a' and @employeesName!= 'b' and @employeesSex = 'c')
    SELECT employeesID,employeesName,employeesSex,employeesPhone,employeesEmail,employeesAddress
     from EmployeesInfo where employeesName like '%'+@employeesName+'%'
    if(@EmployeeID != 'a' and @employeesName = 'b' and @employeesSex = 'c')
    SELECT employeesID,employeesName,employeesSex,employeesPhone,employeesEmail,employeesAddress
     from EmployeesInfo where employeesID like '%'+@EmployeeID+'%'
    else  if(@EmployeeID = 'a' and @employeesName = 'b' and @employeesSex!= 'c')
     SELECT employeesID,employeesName,employeesSex,employeesPhone,employeesEmail,employeesAddress
     from EmployeesInfo where employeesName='%'+@employeesName+'%' and employeesSex=@employeesSex
    程序中的部分
     SqlDataAdapter da = new SqlDataAdapter("Up_Bap_GetAddressBook", conn);
                   da.SelectCommand.CommandType = CommandType.StoredProcedure;
                   da.SelectCommand.Parameters.Add("@EmployeeID", SqlDbType.VarChar,20).Value = employeeID;
                   da.SelectCommand.Parameters.Add("@employeesName", SqlDbType.VarChar,10).Value = employeeName;
                   da.SelectCommand.Parameters.Add("@employeesSex", SqlDbType.VarChar,2).Value = employeeSex;
                   da.Fill(MyDataSet, "AddressBookTable");
      

  5.   

    存储过程不会返回数据集,你在存储过程中写了Select语句并不代表存储过程会把Select的结果集返回给应用程序。
    存储过程通过出参返回数据,如果非要通过存储过程取数据集,似乎可以返回游标。
      

  6.   

    看看下面的代码吧,没问题的                    //创建数据库连接
                        SqlConnection conn = new SqlConnection(connStr);                    //生成执行命令
                        SqlCommand cmd = new SqlCommand("proc_test", conn);
                        //说明是存储过程
                        cmd.CommandType = CommandType.StoredProcedure;                    //添加参数
                        cmd.Parameters.Add("@iXType", SqlDbType.Char);
                        cmd.Parameters["@iXType"].Direction = ParameterDirection.Input;
                        cmd.Parameters["@iXType"].Value = report.xtype.ToString().ToUpper();                    //加载适配器,生成数据集,并关闭数据库连接
                        ds.Clear();
                        conn.Open();
                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                        adapter.Fill(ds, "group");
                        conn.Close();                    gridControl1.DataSource = ds;
      

  7.   

    你程序中直接采用的SqlDataAdapter da = new SqlDataAdapter("Up_Bap_GetAddressBook", conn); 换上面的方式试下吧