Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace Management.DAL
{
    class DataAccessLayer
    {
        SqlConnection SqlConnection;

        public DataAccessLayer()
        {
            SqlConnection = new SqlConnection("server=MOHAMED; database=product_DB; Integrated Securit=true");
        }

       public void open()
        {
           if(SqlConnection.State != ConnectionState.Open)
           {
               SqlConnection.Open();
           }
        }
        public void Close()
       {
            if(SqlConnection.State==ConnectionState.Open)
            {
                SqlConnection.Close();
            }
       }

        public DataTable SelectData(string stored_procedure, SqlParameter[] param)
        {
            SqlCommand sqlcmd = new SqlCommand();
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.CommandText = stored_procedure;

            if(param !=null)
            {
                for(int i = 0; i < param.length; i++)
                {
                    sqlcmd.Parameters.Add(param[i]);
                }
            }
            SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
        }

        public void ExecuteCommand(string stored_procedure, SqlParameter[] param)
        {
            SqlCommand sqlcmd = new SqlCommand();
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.CommandText = stored_procedure;

            if (param !=null)
            {
                sqlcmd.Parameters.AddRange(param);
            }

            sqlcmd.EndExecuteNonQuery();
        }
    }
}
Posted
Updated 25-Mar-15 7:22am
v2
Comments
Thomas Daniels 25-Mar-15 11:15am    
Aside from having it in your namespace name, I don't see 'DAL' used anywhere else. Where do you get the error?
Member 11554901 26-Mar-15 9:31am    
This image shows the problem facing me
http://i.imgur.com/kXS531q.png
Joan Magnet 25-Mar-15 11:18am    
Have you copy/paste from another project?

Change namespace.
Member 11554901 27-Mar-15 12:07pm    
You can download the project from here and see the error or problem
that I do all I can to resolve the problem solutions did not
load the project from here
ـــ
https://app.box.com/s/xzjg9jqygobspeim4l2l3734hdxjnad9
ـــ
F-ES Sitecore 25-Mar-15 13:27pm    
In addition to the other questions, it is impossible to tell the problem from what you have posted. If the code throwing the error is trying to call the class you have posted above, and that code is in a different project, then make sure the client project has a reference to the project your DataAccessLayer class is in.

Aside from this issue, there are things in that code that means I can't see how it will ever work as posted.

1 solution

Add as reference the dll that contains Management.DAL namespace.
 
Share this answer
 

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