2012-03-18 242 views
0

我想使用C#执行SQL Server存储过程。这是我当前的代码:从DLL执行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() - 不是所有的代码路径返回值

回答

2

的错误是很清楚的:

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 
     } 
+0

我在正确的轨道上创建DAL – deception1 2012-03-18 10:01:24

+0

通常,拥有数据访问层总是一个好主意。如果你不确定如何调用存储过程,请看[这里](http://www.csharp-station.com/Tutorial/AdoDotNet)。对于其他任何事情,请更具体地说明你对什么不清楚。 – 2012-03-18 15:42:21

0
  1. 执行程序(类似da.Fill(DS);
  2. return dataset(return ds;)

你要查找的执行过程命令 example

+0

填充DataSet如果没有某种形式的参数(例如绝对似乎不大可能,一个'validate_app_user'存储过程可以做任何事情。用户名,密码???) – Steve 2012-03-18 09:59:41

+0

我会把那些放在我的BO层 – deception1 2012-03-18 10:02:57

+0

login_vald方法的目的是什么?验证用户是否已注册/授权? – Steve 2012-03-18 10:12:28

0

你需要有一个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 
     }