RNathan
Member
Hi,
I have a DataGridView that allows users update rows. The updates work fine. The datasource is bound to only one table. I have a new requirement that needs to be added. When a user updates rows in the grid, I have to update these rows with ModifiedBy and ModifiedDate values. The value of ModifiedBy is user's login name and ModifiedDate is the current date. These fields have to be displayed in the grid as well. I don't want the user to edit these two fields. I would like to feed the values programmatically. I am using VB.Net 2010, MS.NET Framework 4.0. If I use the following code, all the other fields get updated but not ModifiedBy and ModifiedDate.
masterDataAdapter.UpdateCommand = New OleDbCommand("UPDATE Job SET JobName = ?, JobTitle = ?, JobDelete = ?, Comments = ?, ModifiedBy = ?, ModifiedDate = ? WHERE JobName = ?oldJobName", objConnection)
'Create the parameters
masterDataAdapter.UpdateCommand.Parameters.Add("?ModifiedBy", OleDbType.Char, 8).Value = UserName
masterDataAdapter.UpdateCommand.Parameters.AddWithValue("?ModifiedDate", DateTime.Today)
masterDataAdapter.UpdateCommand.Parameters.Add("?JobName", OleDbType.Char, 8, "JobName")
masterDataAdapter.UpdateCommand.Parameters.Add("?oldJobName", OleDbType.Char, 8, "JobName").SourceVersion = DataRowVersion.Original
i = masterDataAdapter.Update(data, "Job")
MessageBox.Show("Number of records updated: " & i)
Thanks in advance...
Rita
I have a DataGridView that allows users update rows. The updates work fine. The datasource is bound to only one table. I have a new requirement that needs to be added. When a user updates rows in the grid, I have to update these rows with ModifiedBy and ModifiedDate values. The value of ModifiedBy is user's login name and ModifiedDate is the current date. These fields have to be displayed in the grid as well. I don't want the user to edit these two fields. I would like to feed the values programmatically. I am using VB.Net 2010, MS.NET Framework 4.0. If I use the following code, all the other fields get updated but not ModifiedBy and ModifiedDate.
masterDataAdapter.UpdateCommand = New OleDbCommand("UPDATE Job SET JobName = ?, JobTitle = ?, JobDelete = ?, Comments = ?, ModifiedBy = ?, ModifiedDate = ? WHERE JobName = ?oldJobName", objConnection)
'Create the parameters
masterDataAdapter.UpdateCommand.Parameters.Add("?ModifiedBy", OleDbType.Char, 8).Value = UserName
masterDataAdapter.UpdateCommand.Parameters.AddWithValue("?ModifiedDate", DateTime.Today)
masterDataAdapter.UpdateCommand.Parameters.Add("?JobName", OleDbType.Char, 8, "JobName")
masterDataAdapter.UpdateCommand.Parameters.Add("?oldJobName", OleDbType.Char, 8, "JobName").SourceVersion = DataRowVersion.Original
i = masterDataAdapter.Update(data, "Job")
MessageBox.Show("Number of records updated: " & i)
Thanks in advance...
Rita