![](/img/trans.png)
[英]Unable to execute stored procedure throught sql server and also from code
[英]Execute a SQL Server stored procedure from a 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_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() - 并非所有代码路径都返回一个值
...意味着你的函数缺少一个带有DataSet
类型对象的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();
return ds; //this is missing
}
您必须查找执行过程命令示例
您需要有一个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(ds); //missing argument from SqlDataAdapter this will fill the ds
return ds; //return filled DataSet
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.