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

hard time inserting data to a table using store procedure

6 Answers 116 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lily
Top achievements
Rank 1
Veteran
Lily asked on 24 Jun 2019, 01:47 AM

Hi,

I'm having some trouble trying to insert my gridview data into a table using store procedure.

Here's the scenario:

I have a dataset1 with a query that selects about 20 columns from left outer joins 3 views (lets call them A, B, C views) and 1 table (D table). 

I created a gridview that fills the gridview that the dataset... of the 20 columns 3 are hidden.

On this D table, I have one column that the cells are empty.  This is where we need to enter the data during runtime.

I created a store procedure that will insert 5 columns from the dataset (3 of the hidden columns, 1 visible, and 1 column where we need to enter the value during runtime) using parameters

On my dataset1 configuration, I added a query that will execute the store procedure (lets call it InsertPIWidthTable, which is D table)

 

Problem:

I got my gridview to populate the data, but can't seem to get what I entered in the cell to store in my D Table.  It says there is no argument given that correspond to the required parameter, but I have all the parameter names correct... So I stuck. Help?

I attached screenshots of everything.  Thank you!

 

This is my code:

private void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
        {
            IEditableObject editableObject = e.Row.DataBoundItem as IEditableObject;
            if (editableObject != null)
            {
                editableObject.EndEdit();
            }
            DataRowView dataRowView = e.Row.DataBoundItem as DataRowView;
            if (dataRowView != null)
            {     

                   this.vW_ProdPrintPageTableAdapter.InsertPIWidthTable();
            }

6 Answers, 1 is accepted

Sort by
0
Lily
Top achievements
Rank 1
Veteran
answered on 24 Jun 2019, 01:51 AM
Also, which event trigger would be best for this: CellValueChanged or CellEndEdit?  I have CellValueChanged right now.
0
Dimitar
Telerik team
answered on 24 Jun 2019, 11:50 AM
Hello Lily,

It seems to me that you need to add the parameters to the stored procedure method.  Here is how to get the values from the DataBoundItem:
private void RadGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
{
    var row = (e.Row.DataBoundItem as DataRowView).Row;
    var plantCode = row["PlantColumn"];
    var orNum = row["OrNum"];
 
    InsertPIWithTable(plantCode, orNum);
 
}

Let me know how this works for you.

Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Lily
Top achievements
Rank 1
Veteran
answered on 24 Jun 2019, 01:31 PM

I'm still getting an error... now its picking on my productionWidth 

in the table, the column name is width

in the gridview that column name is changed to "productionWidth" and binds to the field "width" in the table.  (we have 2 different types of width showing in the gridview which is why I had to change the name)

That sure if this matters...

 

0
Lily
Top achievements
Rank 1
Veteran
answered on 24 Jun 2019, 01:43 PM
and this....
0
Lily
Top achievements
Rank 1
Veteran
answered on 24 Jun 2019, 01:56 PM

I figured it out!  Thanks Dimitar!  You gave me what I needed to figure it out.. I just needed to convert the object to string/decimal and it worked..  Thanks so much!

 

 private void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
        {
            IEditableObject editableObject = e.Row.DataBoundItem as IEditableObject;
            if (editableObject != null)
            {
                editableObject.EndEdit();
            }
            DataRowView dataRowView = e.Row.DataBoundItem as DataRowView;
            if (dataRowView != null)
            {        
                var row = (e.Row.DataBoundItem as DataRowView).Row;
                var plantCode = row["plantCode"];
                var ordNum = row["ordNum"];
                var ordItem = row["ordItem"];
                var machine = row["machine"];
                var productionWidth = row["productionWidth"];

                this.vW_ProdPrintPageTableAdapter.InsertPIWidthTable(Convert.ToString(plantCode),Convert.ToString(ordNum), Convert.ToString(ordItem), Convert.ToString(machine), Convert.ToDecimal(productionWidth));


            }

0
Dimitar
Telerik team
answered on 25 Jun 2019, 11:17 AM
Hi Lily,

I am glad that this works now. Do not hesitate to contact us if you have other questions.

Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Lily
Top achievements
Rank 1
Veteran
Answers by
Lily
Top achievements
Rank 1
Veteran
Dimitar
Telerik team
Share this question
or