how to insert update delete use Radgridview API ?

5 posts, 0 answers
  1. tuonglam
    tuonglam avatar
    3 posts
    Member since:
    Sep 2011

    Posted 07 Sep 2011 Link to this post

    I want to insert update delete use Radgridview API.

    I use automatic



    [img]http://i1143.photobucket.com/albums/n637/new_adm/rad.png[/img]

    And it can load my data.
    [img]http://i1143.photobucket.com/albums/n637/new_adm/rad4.png[/img]
    But when I insert update delete ,it not effect to SQL.Every is not change.
    [img]http://i1143.photobucket.com/albums/n637/new_adm/rad3.png[/img]
    and this is my CS code:
    private void Form1_Load(object sender, EventArgs e)
           {
               // TODO: This line of code loads data into the 'doanvienDataSet.doanvien' table. You can move, or remove it, as needed.
               this.doanvienTableAdapter.Fill(this.doanvienDataSet.doanvien);
                
                
     
           }

    and I insert more code in RowChange event like that.It's can update and delete but it can't insert
    private void radGridView1_RowsChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e)
            {
                     
                    this.doanvienTableAdapter.Update(this.doanvienDataSet.doanvien);
                     
                 
            }


    When i insert it will have a fail:
    There is already an open DataReader associated with this Command which must be closed first.



    I don't know how to close this Command.please help me.thank you very very much!
  2. tuonglam
    tuonglam avatar
    3 posts
    Member since:
    Sep 2011

    Posted 07 Sep 2011 Link to this post

    please help me!
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 08 Sep 2011 Link to this post

    Hello,

    There are also 2 event you should consider, UserAddedRow and UserDeletedRow, you could try performing an update on those, so, basically you could change your code something like this:
        radGridView1.RowsChanged += new GridViewCollectionChangedEventHandler(radGridView1_RowsChanged);
        radGridView1.UserAddedRow += new GridViewRowEventHandler(radGridView1_UserAddedRow);
        radGridView1.UserDeletedRow += new GridViewRowEventHandler(radGridView1_UserDeletedRow);
     
    void radGridView1_UserDeletedRow(object sender, GridViewRowEventArgs e)
    {
        UpdateData();
    }
     
    void radGridView1_UserAddedRow(object sender, GridViewRowEventArgs e)
    {
        UpdateData();
    }
     
    void radGridView1_RowsChanged(object sender, GridViewCollectionChangedEventArgs e)
    {
        if (e.Action != NotifyCollectionChangedAction.Add && e.Action != NotifyCollectionChangedAction.Remove)
        {
            UpdateData();
        }
    }
     
    private void UpdateData()
    {
        this.doanvienTableAdapter.Update(this.doanvienDataSet.doanvien);
    }


    I could not test this because i don't have access to a db now, but if you still have problems i'll try this case asap.

    Until then please try it and let me know.

    Best Regards,
    Emanuel Varga
  5. tuonglam
    tuonglam avatar
    3 posts
    Member since:
    Sep 2011

    Posted 08 Sep 2011 Link to this post

    thank you Emanuel Varga!
    yeah ,i have do like that,but i have a error.
    Operator '!=' cannot be applied to operands of type 'Telerik.WinControls.Data.NotifyCollectionChangedAction' and 'System.Collections.Specialized.NotifyCollectionChangedAction'
    cannot convert from 'WindowsFormsApplication3.doanvienDataSet.doanvienDataTable' to 'WindowsFormsApplication3.doanvienDataSet1.doanvienDataTable'

    thank you very much!
  6. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 08 Sep 2011 Link to this post

    Hi Tuonglam,

    Using the provided information I am not able to locate the issue more precisely, however I think it may be related with the TableAdapter used for Photobucket CRUD operations. Please review and verify your Insert, Update, and Delete command scripts associated with the TableAdapter. You can find more information regarding the usage of TableAdapter commands in the following MSDN article.

    I hope this helps. Please let me know if you need further assistance.

    Best wishes, Julian Benkov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top
UI for WinForms is Visual Studio 2017 Ready