Ejemplo n.º 1
0
 /// <summary>
 //This method is used to attach array of SqlParameters to a SqlCommand.
 /// This method will assign a value of DbNull to any parameter with a direction of
 /// InputOutput and a value of null.
 /// This behavior will prevent default values from being used, but
 /// this will be the less common case than an intended pure output parameter (derived as InputOutput)
 /// where the user provided no input value.
 /// </summary>
 /// <param name="command">The command to which the parameters will be added</param>
 /// <param name="commandParameters">An array of SqlParameters to be added to command</param>
 private static void AttachParameters(NpgsqlCommand command, NpgsqlParameter[] commandParameters)
 {
     try
     {
         if (commandParameters != null)
         {
             foreach (NpgsqlParameter p in commandParameters)
             {
                 if (p != null)
                 {
                     if ((p.Direction == ParameterDirection.InputOutput ||
                          p.Direction == ParameterDirection.Input || p.Direction == ParameterDirection.Output) &&
                         (p.Value == null))
                     {
                         p.Value = DBNull.Value;
                     }
                     command.Parameters.Add(p);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         _ErrorLog.ExceptionWriteIntoTextFile(ex, "Data Access", "AttachParameters", null);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="objcust"></param>
        /// <returns></returns>
        public string InsertCustomerData(Customer objcust)
        {
            SqlConnection Connection = null;

            string result = "";

            try
            {
                Connection = DBConnection.GetConnection();

                using (SqlCommand cmd = new SqlCommand("Usp_InsertUpdateDelete_Customer", Connection))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@CustomerID", objcust.CustomerID);

                    cmd.Parameters.AddWithValue("@Name", objcust.Name);

                    cmd.Parameters.AddWithValue("@Address", objcust.Address);

                    cmd.Parameters.AddWithValue("@Mobileno", objcust.Mobileno);

                    cmd.Parameters.AddWithValue("@Birthdate", objcust.Birthdate);

                    cmd.Parameters.AddWithValue("@EmailID", objcust.EmailID);

                    cmd.Parameters.AddWithValue("@Query", 1);

                    result = cmd.ExecuteScalar().ToString();
                }
            }

            catch (Exception ex)
            {
                ErrorLog.ExceptionWriteIntoTextFile(ex, "InsertCustomerData", "Data access", "CUstomer module");
            }

            finally
            {
                DBConnection.CloseConnection(Connection);
            }
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public List <Customer> GetCustomerData()
        {
            List <Customer> custlist = new List <Customer>();

            DataTable dtCust = new DataTable();

            Customer cobj = new Customer();

            try
            {
                dtCust = CustDAL.GetCustomerData();

                //We can use below query
                //custlist = (from DataRow dr in dtCust.Rows
                //              select new Customer()
                //              {
                //                  CountryCode = Convert.ToString(dr["COUNTRY_CODE"]),
                //                  CountryName = Convert.ToString(dr["COUNTRY_DESC"].ToString())
                //              }).ToList();

                foreach (DataRow dr in dtCust.Rows)
                {
                    cobj.CustomerID = Convert.ToString(dr["CustomerID"].ToString());

                    cobj.Name = dr["Name"].ToString();

                    cobj.Address = dr["Address"].ToString();

                    cobj.Mobileno = dr["Mobileno"].ToString();

                    cobj.EmailID = dr["EmailID"].ToString();

                    cobj.Birthdate = Convert.ToDateTime(dr["Birthdate"].ToString());

                    custlist.Add(cobj);
                }
            }
            catch (Exception ex)
            {
                ErrorLog.ExceptionWriteIntoTextFile(ex, "GetCustomerData", "Business layer", "CUstomer module");
            }
            return(custlist);
        }