Data Access Application Block Tips

If you use typed dataset as your return type between the business layer and data layer and if you are using DAAB, here are some tips.

  • We do not need to define DataAdapter as DAAB is using internally its own generic DataAdapter.
  • DBConcurrency is taken care by DataAdapter but it has to be captured by client as DAAB does not handle any exception on it own. All exceptions will be bubbled up.
  • All tables need to have a timestamp column. It can be of “datetime” datatype.
  • As the return type is strongly typed dataset, there is no need to prepare Insert, Update and Delete command. We need to only pass the connection object or connection string, stored procedure name and datarow instead of parameters. Parameters are fetched from the stored procedure by connecting to the database.
  • Make sure the Datarow (that is from Select statement) has all the columns which the Stored Procedure is expecting. It may have more columns but it should have all the columns which SP needs. AssignParameterValues method loops through the parameter collection and assign the values from the datarow.
  • As all the parameters are fetched from the stored procedure at run time, any parameter addition/deletion will be managed dynamically.(Only from Strongly typed Datasets)
  • For Delete operation,we could not get the row details from the typed dataset as the rowstate has been changed to “Deleted”. As the rowstate is ‘Deleted’ for all the deleted records, we were not able to access any of the column value for that row. So we changed the DAAB code in the following way.

If dataRow.RowState = DataRowState.Deleted Then
 commandParameter.Value = dataRow(commandParameter.ParameterName.Substring(1), DataRowVersion.Original)
Else
 commandParameter.Value = dataRow(commandParameter.ParameterName.Substring(1))
End If

1 Comment

Comments have been disabled for this content.