Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataAdapter.Update() doesn't actually do anything
Message
From
13/06/2003 23:18:11
Keith Payne
Technical Marketing Solutions
Florida, United States
 
 
To
All
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
DataAdapter.Update() doesn't actually do anything
Miscellaneous
Thread ID:
00800071
Message ID:
00800071
Views:
82
I am working on a home-grown business objects framework and I am having trouble getting the SqlDataAdapter.Update method to work correctly. The adapter thinks it is updating correctly, but no changes are passed on to the data source. I have confirmed that the DataSet's RowState is Modified before the Update method is called. The RowState changes to Unchanged and the DataAdapter reports 1 row updated after the Update method is called (which is correct).

I have a breakpoint set in the Update stored procedure but it never get's hit.

Here is the actual code:
- DataAdapter is an SqlDataAdapter.
- DatabaseConnection.sqlconConnection is an SqlConnection
- Dataset's schema is loaded by the DataAdapter via the SelectCommand elsewhere in the code.
        With DataAdapter

            '.TableMappings... (see below)

            .SelectCommand = New SqlCommand("[spPlayerSelect]", DatabaseConnection.sqlconConnection)
            .SelectCommand.CommandType = System.Data.CommandType.StoredProcedure
            .SelectCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
            .SelectCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PlayerID", System.Data.SqlDbType.Int, 4, "PlayerID"))

            .UpdateCommand = New SqlCommand("[spPlayerUpdate]", DatabaseConnection.sqlconConnection)
            .UpdateCommand.CommandType = System.Data.CommandType.StoredProcedure
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Prefix", System.Data.SqlDbType.VarChar, 10, "Prefix"))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@FirstName", System.Data.SqlDbType.VarChar, 15, "FirstName"))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@MiddleName", System.Data.SqlDbType.VarChar, 1, "MiddleName"))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@LastName", System.Data.SqlDbType.VarChar, 20, "LastName"))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Suffix", System.Data.SqlDbType.VarChar, 5, "Suffix"))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.VarChar, 100, "Address"))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.VarChar, 20, "City"))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@State", System.Data.SqlDbType.VarChar, 2, "State"))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PostalCode", System.Data.SqlDbType.VarChar, 15, "PostalCode"))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Phone", System.Data.SqlDbType.VarChar, 15, "Phone"))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Email", System.Data.SqlDbType.VarChar, 50, "Email"))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@CreateDateTime", System.Data.SqlDbType.DateTime, 8, "CreateDateTime"))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Active", System.Data.SqlDbType.Bit, 1, "Active"))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_PlayerID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "PlayerID", System.Data.DataRowVersion.Original, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_Active", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Active", System.Data.DataRowVersion.Original, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_Address", System.Data.SqlDbType.VarChar, 100, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Address", System.Data.DataRowVersion.Original, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_City", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "City", System.Data.DataRowVersion.Original, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_CreateDateTime", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "CreateDateTime", System.Data.DataRowVersion.Original, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_Email", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Email", System.Data.DataRowVersion.Original, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_FirstName", System.Data.SqlDbType.VarChar, 15, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "FirstName", System.Data.DataRowVersion.Original, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_LastName", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "LastName", System.Data.DataRowVersion.Original, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_MiddleName", System.Data.SqlDbType.VarChar, 1, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "MiddleName", System.Data.DataRowVersion.Original, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_Phone", System.Data.SqlDbType.VarChar, 15, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Phone", System.Data.DataRowVersion.Original, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_PostalCode", System.Data.SqlDbType.VarChar, 15, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "PostalCode", System.Data.DataRowVersion.Original, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_Prefix", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Prefix", System.Data.DataRowVersion.Original, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_State", System.Data.SqlDbType.VarChar, 2, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "State", System.Data.DataRowVersion.Original, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_Suffix", System.Data.SqlDbType.VarChar, 5, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "Suffix", System.Data.DataRowVersion.Original, Nothing))
            .UpdateCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PlayerID", System.Data.SqlDbType.Int, 4, "PlayerID"))
        End With

        With DataSet.Tables("Player").Rows(0)
            '.Item("PlayerID") = _PlayerID
            .Item("Prefix") = _Prefix
            .Item("FirstName") = _FirstName
            .Item("MiddleName") = _MiddleName
            .Item("LastName") = _LastName
            .Item("Suffix") = _Suffix
            .Item("Address") = _Address
            .Item("City") = _City
            .Item("State") = _State
            .Item("PostalCode") = _PostalCode
            .Item("Phone") = _Phone
            .Item("Email") = _Email
            .Item("CreateDateTime") = _CreateDateTime
            .Item("Active") = _Active
        End With

        Dim RowsUpdated As Integer
        RowsUpdated = DataAdapter.Update(DataSet, "Player")
I think it may have something to do with the DataAdapter's table mappings. Since the select command is working properly, I think that the DataAdapter has already generated it's own table mappings. However, I have tried using the TableMappings.AddRange(...) generated by the IDE immediately following the creation of the SelectCommand, but I get a "The DataTableMapping.SourceTable is required to be unique, 'Table' already exists in the collection" error. This error doesn't make sense to me because I modeled my code after the autogenerated stuff in a web form. And the same code does not cause an error when running it on a form.

Here is the table mapping code:
'.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Player", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("PlayerID", "PlayerID"), New System.Data.Common.DataColumnMapping("Prefix", "Prefix"), New System.Data.Common.DataColumnMapping("FirstName", "FirstName"), New System.Data.Common.DataColumnMapping("MiddleName", "MiddleName"), New System.Data.Common.DataColumnMapping("LastName", "LastName"), New System.Data.Common.DataColumnMapping("Suffix", "Suffix"), New System.Data.Common.DataColumnMapping("Address", "Address"), New System.Data.Common.DataColumnMapping("City", "City"), New System.Data.Common.DataColumnMapping("State", "State"), New System.Data.Common.DataColumnMapping("PostalCode", "PostalCode"), New System.Data.Common.DataColumnMapping("Phone", "Phone"), New System.Data.Common.DataColumnMapping("Email", "Email"), New System.Data.Common.DataColumnMapping("CreateDateTime", "CreateDateTime"), New System.Data.Common.DataColumnMapping("Active", "Active")})})

Any help is appreciated.
Reply
Map
View

Click here to load this message in the networking platform