Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从DLL执行SQL Server存储过程_C#_Wpf_Sql Server_Stored Procedures_Dll - Fatal编程技术网

C# 从DLL执行SQL Server存储过程

C# 从DLL执行SQL Server存储过程,c#,wpf,sql-server,stored-procedures,dll,C#,Wpf,Sql Server,Stored Procedures,Dll,我想使用C#执行SQL Server存储过程。这是我当前的代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using DBCon; using System.Data; using System.Data.SqlClient; public class LoginDAl { public static DataSet login_

我想使用C#执行SQL Server存储过程。这是我当前的代码:

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

    public class LoginDAl
    {
        public static DataSet  login_vald()
        {
            DBConnect myConnection = new DBConnect();
            SqlCommand comm = new SqlCommand("ph.validate_app_user", myConnection.connection);
            comm.CommandType = CommandType.StoredProcedure;
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter();
        }

}
这是一个用于实践的虚拟项目。DLL是DAL的标准吗?这是一个桌面应用程序。 这是DAL的一部分

错误是

login_vald()-并非所有代码路径都返回值

  • 执行过程(类似于da.Fill(ds);
  • 返回数据集(返回ds;)
  • 您必须查找执行过程命令
    错误很明显:

    login_vald()-并非所有代码路径都返回值

    …意味着您的函数缺少一个
    return
    语句,该语句的对象类型为
    DataSet
    类似:

    public static DataSet  login_vald()
            {
                DBConnect myConnection = new DBConnect();
                SqlCommand comm = new SqlCommand("ph.validate_app_user", myConnection.connection);
                comm.CommandType = CommandType.StoredProcedure;
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter();
    
                return ds;   //this is missing
            }
    

    您需要有一个return语句,还需要用记录填充数据集

            public static DataSet  login_vald()
            {
                DBConnect myConnection = new DBConnect();
                SqlCommand comm = new SqlCommand("ph.validate_app_user", myConnection.connection);
                comm.CommandType = CommandType.StoredProcedure;
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(ds); //missing argument from SqlDataAdapter this will fill the ds
    
               return ds; //return filled DataSet
            }
    

    似乎绝对不可能,
    validate\u app\u user
    存储过程在没有某种参数(例如用户名、密码)的情况下可以做任何事情。我将把它们放在我的BO层中登录方法的目的是什么?要验证用户是否已注册/授权?通常,最好有一个数据访问层。如果不确定如何调用存储过程,请查看。对于任何其他问题,请更具体地说明您不清楚的内容。