Reputation: 1767
I want to execute a SQL Server stored procedure using C#. This is my current code:
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();
}
}
This is a dummy project for practice. Are DLLs the standard for DALs? This is a desktop application. This a part of the DAL.
The error is
login_vald()- not all code paths return a value
Upvotes: 0
Views: 1416
Reputation: 7463
You need to have a return statement, you also need to fill the DataSet with records
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
}
Upvotes: 0
Reputation: 25186
The error is quite clear:
login_vald()- not all code paths return a value
...means that your function is missing a return
statement with an object of type DataSet
something like:
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
}
Upvotes: 2