Error : Update requires a valid UpdateCommand when passed DataRow collection with modified rows

后端 未结 4 2218
孤独总比滥情好
孤独总比滥情好 2020-12-21 01:20

I am using Paging to show data in datagridview, but when i try to Update any data with updatebutton data should be updated In datagridview

4条回答
  •  死守一世寂寞
    2020-12-21 02:22

    Thanks to "@Chris" the code above works for me. I needed to specify the Database Table name that will be updated when I Update. You can read more about that here: DataAdapter: Update unable to find TableMapping['Table'] or DataTable 'Table'

        // This Adapter and Dataset are used for Populating my datagridview, so I use them also when I need to Update the Datagridview
    
        SqlDataAdapter kundeTlfAdapter;
        DataSet kundeTlfDataSet; 
    
            try
            {
                SqlConnection connection = new SqlConnection("Data source=BG-1-PC\\SQLEXPRESS; Database = Advokathuset; User Id = abc; Password = abc;");
                SqlCommand cmd1 = new SqlCommand("Select* From Kunde_Tlf", connection);
                SqlCommandBuilder builder = new SqlCommandBuilder(kundeTlfAdapter);
                kundeTlfAdapter.SelectCommand = cmd1; // cmd1 is your SELECT command
    
                kundeTlfAdapter.Update(kundeTlfDataSet, "Kunde_Tlf"); //I get eror here if I dont add the name of the table that needs Update "Kunde_Tlf"
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message.ToString());
            }
    

提交回复
热议问题