how to CRUD Using Ado.Net @Model datasource & DropDownList grid column

<ejs-grid id="Grid" dataSource="@Model" rowHeight="20" height="200" allowPaging="true" allowFiltering="true" allowSorting="true"

   allowExcelExport="true" toolbarClick="toolbarClick" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel","ExcelExport"})"

  contextMenuItems="@(new List<object>() { "AutoFit", "AutoFitAll", "SortAscending", "SortDescending","Copy", "Edit", "Delete", "Save", "Cancel","PdfExport", "ExcelExport", "CsvExport", "FirstPage", "PrevPage","LastPage", "NextPage"})"

  rowSelected="rowSelected" allowSelection="true" autoFit="true"

  >


HomeController :

public IActionResult Index()

        {

            List<Inventory> inventoryList = new List<Inventory>();


            string connectionString = Configuration["ConnectionStrings:SqlServer"];

            using (SqlConnection connection = new SqlConnection(connectionString))

            {

                connection.Open();

                string sql = "Select * From Inventory";

                //string sql = "ReadInventory";


                SqlCommand command = new SqlCommand(sql, connection);

                //command.CommandType = CommandType.StoredProcedure;


                using (SqlDataReader dataReader = command.ExecuteReader())

                {

                    while (dataReader.Read())

                    {

                        Inventory inventory = new Inventory();


                        inventory.Id = Convert.ToInt32(dataReader["Id"]);

                        inventory.Name = Convert.ToString(dataReader["Name"]);

                        inventory.Price = Convert.ToDecimal(dataReader["Price"]);

                        inventory.Quantity = Convert.ToInt32(dataReader["Quantity"]);

                        inventory.AddedOn = Convert.ToDateTime(dataReader["AddedOn"]);

                        inventory.DelvDate = dataReader[("DelvDate")] == DBNull.Value ? null : Convert.ToDateTime(dataReader["DelvDate"]);


//object column = dataReader.GetOrdinal("DelvDate");

//if (!dataReader.IsDBNull(column))

// inventory.DelvDate = default(DateTime);


//inventory.DelvDate = Convert.ToDateTime(dataReader["DelvDate"]);


inventoryList.Add(inventory);

                    }

                }


                connection.Close();


                ViewBag.inventoryList = inventoryList; // to fill the dropdownlist

ViewBag.Data = inventoryList;


//ViewBag.sort = "Ascending";

//ViewBag.query = "new ej.data.Query().select(['Name', 'ID']).take(0).requiresCount()";

}

            return View(inventoryList);


        }




3 Replies

AR Aishwarya Rameshbabu Syncfusion Team June 21, 2024 09:49 AM UTC

Hi ADMIRAL,


Greetings from Syncfusion support.


After reviewing your query, it is clear that you need to perform CRUD actions in the Syncfusion Grid using ADO.NET data. Upon examining the code example you provided, it appears that you are using SQL connection for your data. To enable CRUD actions with your SQL data, we recommend utilizing the ‘UrlAdaptor’ to bind the data to the Grid, where the data should be returned in the format of result and count. For more detailed information, please consult the documentation and the KB link that explains how to use the UrlAdaptor and perform CRUD operations with SQL using UrlAdaptor.


Documentation Link: UrlAdaptor -Handling-on-demand-grid-actions

KB Link: how-to-bind-sql-server-data-in-asp-net-core-datagrid-using-sqlclient-data-provider


If you need any further assistance or have additional questions, please feel free to contact us.



Regards

Aishwarya R



AP ADMIRAL PH replied to Aishwarya Rameshbabu June 25, 2024 06:00 AM UTC

thank you so much for your concern, I really appreciate it



AR Aishwarya Rameshbabu Syncfusion Team June 26, 2024 07:39 AM UTC

Hi ADMIRAL,


You are most welcome! Please get back to us if you need any other assistance.


Regards

Aishwarya R


Loader.
Up arrow icon