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

how to insert update delete use Radgridview API ?

4 Answers 135 Views
GridView
This is a migrated thread and some comments may be shown as answers.
tuonglam
Top achievements
Rank 1
tuonglam asked on 07 Sep 2011, 08:35 AM
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!

4 Answers, 1 is accepted

Sort by
0
tuonglam
Top achievements
Rank 1
answered on 08 Sep 2011, 01:53 AM
please help me!
0
Emanuel Varga
Top achievements
Rank 1
answered on 08 Sep 2011, 07:39 AM
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
0
tuonglam
Top achievements
Rank 1
answered on 08 Sep 2011, 02:44 PM
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!
0
Julian Benkov
Telerik team
answered on 08 Sep 2011, 02:57 PM
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 >>

Tags
GridView
Asked by
tuonglam
Top achievements
Rank 1
Answers by
tuonglam
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or