예제 #1
0
 protected internal virtual void OnSelect(DataAccessLayerDataSourceEventArgs args)
 {
     if (Select != null)
     {
         Select(this, args);
     }
 }
예제 #2
0
        protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
        {
            DataAccessLayerDataSourceEventArgs eventArgs = new DataAccessLayerDataSourceEventArgs();

            _owner.OnSelect(eventArgs);

            if (eventArgs.QueryCommand == null)
            {
                eventArgs.QueryCommand  = new SqlCommand("select null as ColumnName");
                arguments.TotalRowCount = 0;
                return(new DataTable().AsEnumerable());
            }

            SqlConnection conn = (SqlConnection)_owner.CreateDataManager()._db.Connection;

            eventArgs.QueryCommand.Connection = conn;
            conn.Open();

            if (eventArgs.QueryCommand.CommandText.Trim().ToUpper().StartsWith("SELECT"))
            {
                SqlCommand cmdRecordCount = eventArgs.QueryCommand.Clone();
                cmdRecordCount.CommandText = "select Count(*) as RecordCount " + cmdRecordCount.CommandText.Substring(cmdRecordCount.CommandText.ToUpper().IndexOf("FROM"));
                arguments.TotalRowCount    = (int)cmdRecordCount.ExecuteScalar();
            }
            else
            {
                arguments.TotalRowCount = 1;
            }


            SqlDataAdapter da     = new SqlDataAdapter(eventArgs.QueryCommand);
            DataSet        result = new DataSet();

            if (arguments.MaximumRows > 0 && arguments.StartRowIndex >= 0)
            {
                da.Fill(result, arguments.StartRowIndex, arguments.MaximumRows, "Table");
            }
            else
            {
                da.Fill(result);
            }

            return(result.Tables[0].AsEnumerable());
        }