deception1
deception1

Reputation: 1767

Execute a SQL Server stored procedure from a DLL

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

Answers (3)

heads5150
heads5150

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

Frank Bollack
Frank Bollack

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

elrado
elrado

Reputation: 5282

  1. execute procedure (something like da.Fill(ds);)
  2. return dataset (return ds;)

You have to look up for execute procedure command example

Upvotes: 0

Related Questions