hard time inserting data to a table using store procedure

7 posts, 0 answers
  1. Lily
    Lily avatar
    14 posts
    Member since:
    Feb 2019

    Posted 23 Jun Link to this post

    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();
                }

  2. Lily
    Lily avatar
    14 posts
    Member since:
    Feb 2019

    Posted 23 Jun in reply to Lily Link to this post

    Also, which event trigger would be best for this: CellValueChanged or CellEndEdit?  I have CellValueChanged right now.
  3. Dimitar
    Admin
    Dimitar avatar
    2737 posts

    Posted 24 Jun Link to this post

    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.
  4. Lily
    Lily avatar
    14 posts
    Member since:
    Feb 2019

    Posted 24 Jun in reply to Dimitar Link to this post

    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...

     

  5. Lily
    Lily avatar
    14 posts
    Member since:
    Feb 2019

    Posted 24 Jun Link to this post

    and this....
  6. Lily
    Lily avatar
    14 posts
    Member since:
    Feb 2019

    Posted 24 Jun Link to this post

    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));


                }

  7. Dimitar
    Admin
    Dimitar avatar
    2737 posts

    Posted 25 Jun Link to this post

    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.
Back to Top