Hi,
I am making a windows application, and I don't have any idea about splitting code like Business Layer, and Data Access Layer. Now, I have created UI as Windows Project, Business Layer as Class Library , and Data Access Layer as another Class Library.
I want to make sure that the below sample code I have created for Data Access Layer is right for the architecture. I am aiming to pass the values as Dictionary object to DAL, and DAL will call the stored procedure to perform the task requested by BL.
Is the below code technically correct ??
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace HRDAL
{
public class procExec
{
SqlConnection con =null;
public procExec(string conStr)
{
con = new SqlConnection(conStr);
con.Open();
}
public KeyValuePair<int, string> ExecuteSP(string SPName, Dictionary<string, string> SPParameters)
{
if (con.State == ConnectionState.Open)
{
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = SPName;
foreach(KeyValuePair<string, string> Pm in SPParameters)
com.Parameters.Add(new SqlParameter(Pm.Key, Pm.Value));
return new KeyValuePair<int, string>(1000, "Success");
}
else
return new KeyValuePair<int, string>(1001, "No Connection to the Server");
}
public ~procExec()
{
con.Close();
}
}
}