Alex Zhukovskiy Alex Zhukovskiy - 5 months ago 33
SQL Question

Submitting Changes pure SqlCommand

I need to get 2-way binding DB to DataGrid, so I'm using this method:

private void SetTable(string tableName)
var dataGridView1 = new DataGridView { DataSource = GetData(tableName), Dock = DockStyle.Fill };
groupBox1.Text = tableName;

private static DataTable GetData(string tableName)
using (var connection = new SqlConnection(ConnectionString))
var command = new SqlCommand(string.Format("SELECT * FROM {0}", tableName), connection);

var adapter = new SqlDataAdapter(command);
var result = new DataTable();
return result;

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

so I have one-way binding. So I'd like to do some changes and after send them back to db. So question is simple: should I do it manually or analogue of L2S
exists? I should use SQL requests only. No EF, No L2S and so on.

So I'd like to get some modified/added/removed rows from
and update them in database.
I can do it manually, using 2 lists and after make an except query, but I'd like to get it automatically.

Answer Source

You can determine what has changed by calling GetChanges() and/or update directly by using a TableAdapter.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download