S G

S G

  • 1.7k
  • 2
  • 752

How to save changes to the Table View via C# application?

Sep 21 2015 12:59 PM
Example:
- Create a table - SQL Server 2008 R
- Create a view  - SQL Server 2008 R
- Create a Form - C# 2013
- Use DataGridview to populate the Table View Values
-- Add Button - Save
-- Add the code as below.
Error message: UPDATE - Invalid
There is a betterway to update the Table View? Not the Table.
Thanks for your help. 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace WindowsFormsApplication3

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{


this.view_TestTableAdapter.Fill(this._TestDataSet.View_Test);

}

private void button1_Click(object sender, EventArgs e)

{

try

{

this.Validate();

this.viewTestBindingSource.EndEdit();

this.view_TestTableAdapter.UPDATE(this.TestDataSet.View_Test);

MessageBox.Show("Update Ok)");

}

catch (System.Exception ex)

{

MessageBox.Show("Update failed");

}

}

}

}