Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
can i use this code in the DAL? or it can be a part of DAL?
C#
public static DataTable Get(string CommandText, SqlParameter[] Params)
    {
        try
        {
            using (SqlConnection connection = new SqlConnection(Login.getConnection()))
            {
                SqlCommand cmd = new SqlCommand();
               
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = CommandText;
                cmd.Parameters.AddRange(Params);
                cmd.Connection = connection;
                cmd.CommandTimeout = 600;
                connection.Open();

                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                adapter.Fill(dt);
                return dt;
            }
        }
        catch (Exception ex) { throw ex; }
    }

where Login.getConnection()is just return the connection string.
Posted
Updated 13-Feb-12 7:55am
v2
Comments
Keith Barrow 13-Feb-12 14:55pm    
I just want to say I ageee 100% with Christian Graus's answer, I think Rahul Dhoble may be confusion DAL with assembly or dll. In any case I disagree with Rahul.

I disagree. The connection string needs to be part of the DAL, and the rest of it is pure DAL code. Even if it's stored in the app.config and is passed to the DAL once and stored there, the connection string needs to be in the DAL, no other layer should ever use it.
 
Share this answer
 
No this can't

Because DAL is something like you build it to make .dll and refer it into number of project . Since you are using Login.SqlConnection . It does not make sense either to make this code as part of DAL


Hope this helps and you agree to accept and vote the answer otherwise revert back with your queries.
--Rahul D.
 
Share this answer
 
Comments
Keith Barrow 13-Feb-12 14:49pm    
My Vote of 2: The code supplied by the OP is 100% Data Access Layer (DAL) type code. Any layers (Object Model or Presentation Layers etc). You seem to be confusing dll with DAL. See Christian's response.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900