none
How to get affected rows number from a TableAdpter. RRS feed

  • Question

  • I have a data set populated from data base stored procedure objects.There are some INSERT queries which are mapped to queriesTableAdapter and not TABLE objects.when they are executed inside application how should I get the number of rows affected after a successful insert and show it in a control like message box.Thanks.
    Wednesday, May 9, 2012 5:55 PM

Answers

  • Hi mortaza.mkr,

    Welcome to MSDN Forum.

    I wrote a demo to demonstrate how to get the count of affected rows. Below are the screen shot of my Windows Form and the code behind.

    Code

    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void playerBindingNavigatorSaveItem_Click(object sender, EventArgs e)
            {
                this.Validate();
                this.playerBindingSource.EndEdit();
                this.tableAdapterManager.UpdateAll(this.testDataSet);
    
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                // TODO: This line of code loads data into the 'testDataSet.Player' table. You can move, or remove it, as needed.
                this.playerTableAdapter.Fill(this.testDataSet.Player);
    
            }
    
            private void btnSave_Click(object sender, EventArgs e)
            {
                this.Validate();
                this.playerBindingSource.EndEdit();
                int count = this.playerTableAdapter.Update(this.testDataSet.Player);
                MessageBox.Show(count.ToString());
            }
        }

    Best Regards

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by mortaza.mkr Thursday, May 10, 2012 2:00 PM
    Thursday, May 10, 2012 3:12 AM
    Moderator