Made in Visual Studio C # a program for recording, editing and deleting data from a single-table Microsoft SQL Server database
The program successfully writes new data to the database table, but when you try to delete or edit data in any of the rows of the table, the following message appears: "You need a valid UpdateCommand to update when you transfer the DataRow collection with modified rows." That is, changes are written to the table of the application itself in the DataGridView, but when you try to save this change by clicking a button, this message appears, and nothing changes in the database.
If you try to delete the entire row with the key from the BindingNavigator, no messages appear, the row in the application table is deleted, but nothing changes in the database
As a result, at the moment there is only a new data entry into the database.
Part of the program code:
namespace WindowsFormsApplication1 {public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'spisok_zakazovDataSet.Table_1' table. You can move, or remove it, as needed. this.table_1TableAdapter.Fill(this.spisok_zakazovDataSet.Table_1); } private void button1_Click(object sender, EventArgs e) { try { this.Validate(); this.table1BindingSource.EndEdit(); this.table_1TableAdapter.Update(this.spisok_zakazovDataSet.Table_1); MessageBox.Show("Update successful"); } catch (System.Exception ex) { MessageBox.Show("Update failed"); } } } }
Program + database entirely: https://yadi.sk/d/8licJpe13Hnq5a
tableAdapter.UpdateCommand = "update ..."with sql code to update the table. - Alexander Petrov