web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / CRUD Operations using ...
Power Apps
Unanswered

CRUD Operations using custom data provider with Virtual Table

(0) ShareShare
ReportReport
Posted on by 14

Hi All,

 I created C# Plugins for CRUD operations by referring to this article:

 

"Custom virtual table provider with CRUD operations"

https://docs.microsoft.com/en-us/powerapps/developer/data-platform/virtual-entities/sample-ve-provider-crud-operations.

 

External Database used: Azure SQL dB.

App: Model Driven App in Maker Portal (https://make.powerapps.com)

Registered the Assembly using "PluginRegistration.exe"

Created Data Provider, Data Source

Created Virtual Table, Views, Forms in Model Driven App

Created Sub Area (Form) in Model Driven App and used Virtual Table as Datasource

 

All the records are displayed on Virtual Table's View (Default All View) and Data Tab.

 

I am encountering two issues

1. While running the App, only one record (last record) is displayed on the page, but record count showing correctly.

 

2. Also while performing Add/Edit the following error occurs:

"The specified domain does not exist or cannot be contacted
An unexpected error occurred from ISV code. Error code: 0x80040224"

 

Also attached screen captures. Request your suggestions/help to resolve the issues

 

Regards

 

Mohan

 

 

I have the same question (0)
  • MayankP Profile Picture
    464 on at

    Hi @MohanKann21 

    can you share your retrieve multiple plug in code here ? so we can check and rule out there is no issue at this end..

  • MohanKann21 Profile Picture
    14 on at

    Hi MayankP,

     

    Thanks for your reply.

     

    Here is the Retrieve Multiple Plugin Code:

     

    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Extensions;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    namespace Test.Dataverse.VirtualTable.Plugins
    {
    public class RetrieveMultiple : IPlugin
    {
    public void Execute(IServiceProvider serviceProvider)
    {
    IPluginExecutionContext context = (IPluginExecutionContext)
    serviceProvider.GetService(typeof(IPluginExecutionContext));

    EntityCollection collection = new EntityCollection();

    string cmdString = "SELECT [Id],[NameType], [Name],[FullName],[Pattern]," +
    "[IsError],[IsMovedOut], FROM [dbo].[Person]";
    SqlConnection connection = Connection.GetConnection();
    using (SqlCommand command = connection.CreateCommand())
    {
    command.CommandText = cmdString;
    connection.Open();
    try
    {
    using (SqlDataReader reader = command.ExecuteReader())
    {
    while (reader.Read())
    {
    Entity e = new Entity("new_person");

    e.Attributes.Add("new_id", reader.GetInt32(0));

    e.Attributes.Add("new_nametype", reader.IsDBNull(1) ? "" : reader.GetString(1));
    e.Attributes.Add("new_name", reader.IsDBNull(2) ? "" : reader.GetString(2));
    e.Attributes.Add("new_fullname", reader.IsDBNull(3) ? "" : reader.GetString(3));
    e.Attributes.Add("new_pattern", reader.IsDBNull(4) ? "" : reader.GetString(4));
    e.Attributes.Add("new_isrror", reader.IsDBNull(5) ? 0 : reader.GetInt32(5));
    e.Attributes.Add("new_ismovedout", reader.IsDBNull(6) ? false : reader.GetBoolean(6));

    collection.Entities.Add(e);
    }
    }
    }
    catch (Exception ex)
    {
    throw new InvalidPluginExecutionException("Service Error", ex);
    }
    finally
    {
    connection.Close();
    }
    context.OutputParameters["BusinessEntityCollection"] = collection;
    }
    }
    }
    }

     

    Thanks,

     

    Mohan

  • MayankP Profile Picture
    464 on at

    Hi @MohanKann21 

     

    may be this might not be issue but in following line there is extra comma ....

     

    string cmdString = "SELECT [Id],[NameType], [Name],[FullName],[Pattern]," +
    "[IsError],[IsMovedOut], FROM [dbo].[Person]";

     

    I suggest change this to be like this and see if this resolves the issue....

     

    string cmdString = "SELECT [Id],[NameType], [Name],[FullName],[Pattern]," +
    "[IsError],[IsMovedOut] FROM [dbo].[Person]";

     

  • MohanKann21 Profile Picture
    14 on at

    Hi MayankP,

     

    Thanks for your help.

     

    Yes It is typos while sharing the code here and it is corrected... 

     

    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Extensions;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    namespace Test.Dataverse.VirtualTable.Plugins
    {
    public class RetrieveMultiple : IPlugin
    {
    public void Execute(IServiceProvider serviceProvider)
    {
    IPluginExecutionContext context = (IPluginExecutionContext)
    serviceProvider.GetService(typeof(IPluginExecutionContext));

    EntityCollection collection = new EntityCollection();

    string cmdString = "SELECT [Id],[NameType], [Name],[FullName],[Pattern]," +
    "[IsError],[IsMovedOut] FROM [dbo].[Person]";
    SqlConnection connection = Connection.GetConnection();
    using (SqlCommand command = connection.CreateCommand())
    {
    command.CommandText = cmdString;
    connection.Open();
    try
    {
    using (SqlDataReader reader = command.ExecuteReader())
    {
    while (reader.Read())
    {
    Entity e = new Entity("new_person");

    e.Attributes.Add("new_id", reader.GetInt32(0));

    e.Attributes.Add("new_nametype", reader.IsDBNull(1) ? "" : reader.GetString(1));
    e.Attributes.Add("new_name", reader.IsDBNull(2) ? "" : reader.GetString(2));
    e.Attributes.Add("new_fullname", reader.IsDBNull(3) ? "" : reader.GetString(3));
    e.Attributes.Add("new_pattern", reader.IsDBNull(4) ? "" : reader.GetString(4));
    e.Attributes.Add("new_iserror", reader.IsDBNull(5) ? 0 : reader.GetInt32(5));
    e.Attributes.Add("new_ismovedout", reader.IsDBNull(6) ? false : reader.GetBoolean(6));

    collection.Entities.Add(e);
    }
    }
    }
    catch (Exception ex)
    {
    throw new InvalidPluginExecutionException("Service Error", ex);
    }
    finally
    {
    connection.Close();
    }
    context.OutputParameters["BusinessEntityCollection"] = collection;
    }
    }
    }
    }

     

    But the issue persists. 

     

    Regards,

     

    Mohan

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard