Wednesday, 11 September 2013

Using C# I can't get the changes I make in my GridView to save to the SQL Database

Using C# I can't get the changes I make in my GridView to save to the SQL
Database

Here is my code. I am using windows forms. Everything populates the grid
view. I want to be able to make changes to each column in the view. What
step am I missing to get the changes I made to save back to the SQL
Database?
private void button1_Click(object sender, EventArgs e)
{
myConnection.Open();
Cursor.Current = Cursors.WaitCursor;
string query = @"select EmployeeId[Employee], DateIn, cast (timein
as time(0)) [TimeIn], dateout, cast(timeout as time(0))[Time
Out], job ,
costcode from Data_TimeCards_T WHERE (EmployeeID
LIKE '%[^a-zA-Z0-9]%') or (job LIKE
'%[^a-zA-Z0-9]%')";
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query,
myConnection);
OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
DataTable dTable = new DataTable();
dataGridView1.DataSource = dTable;
dAdapter.Fill(dTable);
DataGridView dgView = new DataGridView();
BindingSource bSource = new BindingSource();
bSource.DataSource = dTable;
dgView.DataSource = bSource;
dAdapter.Update(dTable);
myConnection.Close();
}

No comments:

Post a Comment