entlib UpdateDataSet how to update the database?

  • Thread starter Thread starter Eduardo Silva
  • Start date Start date
E

Eduardo Silva

Hi every body i new in dot.net and i am tring to update a table with a data
set using entlib i found the way to doit one by one but is any way to doit
in one command?

Code Sample

Dim dbCatalyst As Microsoft.Practices.EnterpriseLibrary.Data.Database =
DatabaseFactory.CreateDatabase("CATALYST")

Dim sqlCatalyst As String = Me.sqlRecipient

Dim dbCatalystCommand As DbCommand =
dbCatalyst.GetSqlStringCommand(sqlCatalyst)

Dim CatalystDataSet As DataSet =
dbCatalyst.ExecuteDataSet(dbCatalystCommand)

Dim CatalystTable As DataTable = CatalystDataSet.Tables(0)

'iseb

Dim dbISEB As Microsoft.Practices.EnterpriseLibrary.Data.Database =
DatabaseFactory.CreateDatabase("ISEB")

Dim sqlISEB As String = "select * from tmpReportViewer"

Dim tmpReportViewerDataSet As New DataSet

Dim dbISEBCommand As DbCommand = dbISEB.GetSqlStringCommand(sqlISEB)

Dim tmpReportViewerTable As String = "tmpReportViewer"

dbISEB.LoadDataSet(dbISEBCommand, tmpReportViewerDataSet,
tmpReportViewerTable)

Dim table As DataTable = tmpReportViewerDataSet.Tables(tmpReportViewerTable)

table = CatalystTable

Dim rowsAffected As Integer = dbISEB.UpdateDataSet(tmpReportViewerDataSet,
tmpReportViewerTable, Nothing, Nothing, Nothing, UpdateBehavior.Standard)
 
Eduardo,

Your last line (dbISEB.UpdateDataSet) has no DBCommand objects to do this.
They are set to Nothing, Nothing, Nothing. Normally you would use three
stored procedures (SQL), an insert, an update and a delete procedure.

e.g.
cmdInsert = dbISEB.GetStoredProcCommand("sp_myInsert")
''' Add your sproc parameters here! - see AddInParameter method
cmdUpdate = dbISEB.GetStoredProcCommand("sp_myUpdate")
''' Add your sproc parameters here!
cmdDelete = dbISEB.GetStoredProcCommand("sp_myDelete")
''' Add your sproc parameters here!

You would then replace the Nothing, Nothing, Nothing with cmdInsert,
cmdUpdate, cmdDelete. Note: If all you are doing is performing one type of
action (e.g. Insert) then you can set the others to Nothing.

BTW microsoft.public.vsnet.enterprise.tools would probably be a better
newsgroup to post EntLib queries.

Paul
 
Back
Top