C# 从DLL执行SQL Server存储过程
我想使用C#执行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_
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()-并非所有代码路径都返回值
错误很明显: 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层中登录方法的目的是什么?要验证用户是否已注册/授权?通常,最好有一个数据访问层。如果不确定如何调用存储过程,请查看。对于任何其他问题,请更具体地说明您不清楚的内容。