This is a migrated thread and some comments may be shown as answers.

Kendo UI grid use Datatable can't insert, update, delete data in SQL

2 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pham
Top achievements
Rank 1
Pham asked on 04 Jun 2015, 03:09 PM

Hello Telerik team

 I'm using , use DataTable to load data grid.

This is my Index code

 

@model SystemDataDataTable
 
@HtmlKendo)Grid<dynamic>()
    Name"Grid")
            Columnscolumns =>
            {
                Bound"ID");
                Bound"Name");
                Bound"UnitPrice")Width100);
                Bound"UnitsInStock")Width100);
                 
                Command => Edit); Destroy);)Width160);
            })
    toolbar => toolbarCreate))
    )
    )
    ed=>ModeGridEditModePopUp))
    Filterable)
     =>
        Ajax)       
        Modelmodel =>
            {
                 id = ModelPrimaryKey0]ColumnName;
                Idid);
                 (SystemDataDataColumn column in ModelColumns)
                {
                     field = modelFieldcolumnColumnName, columnDataType);
                     (columnColumnName == id)
                    {
                        Editablefalse);
                    }
                     
                }               
            })
                //Aggregatesa =>
                //{
                //    //Add"UnitPrice", typeofdecimal?))Sum);
                //    //Add"UnitsInStock", short?))Average)Max);
                //    Add"Total (Price*Quantity)", short?));
                //})
                     
        Readread => readAction"GetProductsList", "Home"))
       Destroydestroy => destroyAction"DestroyProduct", "Home"))
    )
)

 

 This is my HomeController

;
SystemCollectionsGeneric;
SystemLinq;
SystemWeb;
SystemWebMvc;
KendoMvcUI;
KendoMvcExtensions;
SystemData;
SystemDataSqlClient;
SystemConfiguration;
 
GridBindingToDataTableControllers
{
     class HomeController Controller
    {
         string str_connection = ConnectionStrings"KloonDB"]ConnectionString;         
         ActionResult Index)
        {
            DataTable dt_products = GetProductsList);
             
             
             Viewdt_products);
        }
 
         ActionResult About)
        {
             View);
        }
 
         ActionResult GetProductsList[DataSourceRequest] DataSourceRequest request)
        {
            DataTable products = GetProductsList);
 
             (requestAggregatesAny))
            {
                AggregatesEach =>
                {
                    AggregatesEacha =>
                    {
                         = productsColumnsMember]DataType;
                    });
                });
            }
 
             JsonproductsToDataSourceResultrequest));
        }        
         ActionResult DestroyProduct[DataSourceRequest] DataSourceRequest request,
             )
        {
            );
            //Delete Product at server side
            DataTable dt_products = GetProductsList);           
            // grid
             Jsondt_productsToDataSourceResultrequest));
        }
         DataTable GetProductsList)
        {
             str_SQLSelectcommand = "SELECT IDNamePriceQuantityStatusIdColor from Tbl_Products";
             ( = new SqlDataAdapterstr_SQLSelectcommand, str_connection))
            {
                 = new DataTable);
                Fill);
                FillSchema, SchemaTypeMapped);
                 ;
            }
        }        
 
         void DestroyProductInDatabase )
        {
             (SqlCommand command = new SqlCommand))
            {
                Connection = new SqlConnectionstr_connection);
                CommandType = CommandTypeText; //I don't want to use
                CommandText = "Delete from [Tbl_Products] where [ProductID] = @ProductID";
                command.Parameters.Add(new SqlParameter("@ProductID", SqlDbType.Int)).Value = iProductID;   
                ExecuteNonQuery);
            }
        }        
    }
}
 

 I set breakpoint in VS 2013 and when I click delete button in . It won't jump to breakpoint in VS 2013. When I set breakpoint , it works fine.

 Can someone help me why I can't delete data in .

 Thank you.

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 08 Jun 2015, 09:51 AM
Hello,

The Select statement from the code that you provided:
string str_SQLSelectcommand = "SELECT ID,Name,Price,Quantity,ExpiredDate,StatusId,Color from Tbl_Products";
does not seem to contain a field named iProductID. Therefore an exception will be thrown for missing not Nullable parameter and the method will not be called. You should include the id field which seems to be ProductID from the delete statement in the loaded data and change the action parameter name to be the same.



Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Pham
Top achievements
Rank 1
answered on 08 Jun 2015, 12:42 PM

I saw it.

Thank you

Tags
Grid
Asked by
Pham
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Pham
Top achievements
Rank 1
Share this question
or