На главную Наши проекты:
Журнал   ·   Discuz!ML   ·   Wiki   ·   DRKB   ·   Помощь проекту
ПРАВИЛА FAQ Помощь Участники Календарь Избранное RSS
msm.ru
  
> Ошибка: System.StackOverflowException , Ошибка: System.StackOverflowException
    Здравствуйте! Столкнулся с проблемой, при обращении к классу DataAccessLayer выдает ошибку System.StackOverflowException
    Сам класс:
    ExpandedWrap disabled
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Data.OleDb;
      using System.Data;
      using System.Collections;
      using System.IO;
       
      namespace View_DBF_File.DAL
      {
          public class DataAccessLayer
          {
              #region Properties
              private string ConnectionString
              {
                  get
                  {
                      return View_DBF_File.Properties.Settings.Default.DBFConnStr;
                  }
              }
              private OleDbConnection DBF_Connection
              {
                  get
                  {
                      if (this.dbfConnection == null)
                      {
                          this.dbfConnection = new OleDbConnection(this.ConnectionString);
                      }
                      return this.dbfConnection;
                  }
              }
              
              #endregion
       
              #region Fields
              private OleDbConnection dbfConnection;
              private OleDbDataAdapter tableAdapter;  
              //private DataTable all_DBF_File;
              #endregion
       
       
              private OleDbDataAdapter DBF_Table
              {
                  get
                  {
                      if (this.tableAdapter == null)
                      {
                          this.tableAdapter = new OleDbDataAdapter();
       
                          OleDbCommand dbfCommand = new OleDbCommand();
                          dbfCommand.CommandText = " select * from @tableName";
                          dbfCommand.CommandType = CommandType.Text;
                          dbfCommand.Connection = this.DBF_Connection;
       
                          OleDbParameter mySqlParameter =
                              new OleDbParameter("@tableName", OleDbType.VarChar, 0);
                          //MySqlParameter.Direction = ParameterDirection.Input;
       
                          this.tableAdapter.SelectCommand = dbfCommand;
                      }
                      return this.tableAdapter;
                  }
              }
       
              public DataTable GetDBF_Table(string tableName)
              {
                  this.DBF_Table.SelectCommand.Parameters["@tableName"].Value = tableName;
       
                  try
                  {
                      DataTable classes = new DataTable("Table");
                      this.DBF_Table.Fill(classes);
                      return classes;
                  }
                  catch
                  {
                      return null;
                  }
              }
          }
      }

    Сама форма:
    ExpandedWrap disabled
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
      using View_DBF_File.DAL;
      using System.Collections;
      using System.IO;
       
      namespace View_DBF_File
      {
          public partial class MainForm : Form
          {
              
              
              public MainForm()
              {
                  InitializeComponent();
              }
              public DataAccessLayer DataAccessLayer
              {
                  get
                  {
                      if (this.DataAccessLayer == null)
                      {
                          this.m_dataAccessLayer = new DataAccessLayer();
                      }
                      return this.m_dataAccessLayer;
                  }
              }
              private DataAccessLayer m_dataAccessLayer;
              public DataTable DBF_Table
              {
                  get
                  {
                      return this.DataAccessLayer.GetDBF_Table(Path.GetFileName(cb_Files.Text.Trim()));
                  }
              }
              private void bt_Review_Click(object sender, EventArgs e)
              {
                  this.dgv_Review.DataSource = this.DBF_Table;
                  
              }
       
              private void cb_Files_Click(object sender, EventArgs e)
              {
                
                  cb_Files.Items.Clear();
                  foreach (string File in Directory.GetFiles("D:\\KVPLATA\\BAZA6"))
                  {
                      cb_Files.Items.Add(Path.GetFileName(File));
                  }
              }
          }
      }
      Цитата Dmitriy78781 @

      public DataAccessLayer DataAccessLayer
      {
      get
      {
      if (this.DataAccessLayer == null)

      Я не уверен что ошибка именно тут, но разве логично называть пропертю ее типом? Попробуй дать ей другое название, чтобы не было путаницы. Из первого твоего коментария - могу только предположить что именно тут ошибка и летит. И проверять нужно не саму проперти -> if(this.DataAccessLayer== null), а член класса
      ExpandedWrap disabled
                        if (this.m_dataAccessLayer == null)
                        {
                            this.m_dataAccessLayer = new DataAccessLayer();
                        }
                        return


      Добавлено
      Скорее всего из за этого и летит исключение о переполнении стэка.
      0 пользователей читают эту тему (0 гостей и 0 скрытых пользователей)
      0 пользователей:


      Рейтинг@Mail.ru
      [ Script execution time: 0,0215 ]   [ 16 queries used ]   [ Generated: 28.03.24, 11:53 GMT ]