Subject: Dataset Merge Problem
Posted By: jpitzer Post Date: 1/9/2004 10:01:29 AM
I'm developing an application using XML Web Reference, SQL Server database, and Visual Studio.net 2003.
I have a web form which users populate with data (or change data) and click a button to save the data to the database. I use a stored procedure to accomplish this and return the dataset back to the page to re-populate the dataset with the corrected data.
My problem is that the data gets saved properly to the database, but does not get "Merged" back into the dataset properly -- the old data persists.
Here's some code from the .asmx file:
    <WebMethod(Description:="This XML Web service updates Employees " _
        & "from a supplied EID")> _
    Public Function UpdateEIDEmp(ByVal iEID As Integer, ByVal iLName As String, _
    ByVal iFName As String, ByVal iJob As String, ByVal iSuper As Integer, _
    ByVal iPhone As String, ByVal iPID As String, ByVal iEndda As String, _
    ByVal iBegda As String, ByVal iuserChange As String, ByVal idtChange As String) As DataSet

        Dim daEIDEmp As SqlDataAdapter
        Dim dsEmp1 As New dsEmp
        Dim workParam As SqlParameter = Nothing

        'set up the stored procedure
        daEIDEmp = _
            New SqlDataAdapter("sp_UpdateEmp", SqlConnection1)
        daEIDEmp.SelectCommand.CommandType = _
            CommandType.StoredProcedure

        'add the EID input parameter
        workParam = New SqlParameter("@EID", _
            System.Data.SqlDbType.Int)
        workParam.Direction = ParameterDirection.Input
        workParam.Value = iEID
        daEIDEmp.SelectCommand.Parameters.Add(workParam)

        workParam = New SqlParameter("@PID", _
            System.Data.SqlDbType.Int)
        workParam.Direction = ParameterDirection.Input
        workParam.Value = iPID
        daEIDEmp.SelectCommand.Parameters.Add(workParam)

        workParam = New SqlParameter("@Name_F", _
            System.Data.SqlDbType.NVarChar, 20)
        workParam.Direction = ParameterDirection.Input
        workParam.Value = iFName
        daEIDEmp.SelectCommand.Parameters.Add(workParam)

        workParam = New SqlParameter("@Name_L", _
            System.Data.SqlDbType.NVarChar, 20)
        workParam.Direction = ParameterDirection.Input
        workParam.Value = iLName
        daEIDEmp.SelectCommand.Parameters.Add(workParam)

        workParam = New SqlParameter("@Job", _
            System.Data.SqlDbType.NVarChar, 20)
        workParam.Direction = ParameterDirection.Input
        workParam.Value = iJob
        daEIDEmp.SelectCommand.Parameters.Add(workParam)

        workParam = New SqlParameter("@Begda", _
            System.Data.SqlDbType.DateTime)
        workParam.Direction = ParameterDirection.Input
        workParam.Value = iBegda
        daEIDEmp.SelectCommand.Parameters.Add(workParam)

        workParam = New SqlParameter("@Endda", _
            System.Data.SqlDbType.DateTime)
        workParam.Direction = ParameterDirection.Input
        workParam.Value = iEndda
        daEIDEmp.SelectCommand.Parameters.Add(workParam)

        workParam = New SqlParameter("@super", _
            System.Data.SqlDbType.Int)
        workParam.Direction = ParameterDirection.Input
        workParam.Value = iSuper
        daEIDEmp.SelectCommand.Parameters.Add(workParam)

        workParam = New SqlParameter("@PhoneLoc", _
            System.Data.SqlDbType.NVarChar, 25)
        workParam.Direction = ParameterDirection.Input
        workParam.Value = iPhone
        daEIDEmp.SelectCommand.Parameters.Add(workParam)

        workParam = New SqlParameter("@userChange", _
            System.Data.SqlDbType.NVarChar, 12)
        workParam.Direction = ParameterDirection.Input
        workParam.Value = iuserChange
        daEIDEmp.SelectCommand.Parameters.Add(workParam)

        workParam = New SqlParameter("@dtChange", _
            System.Data.SqlDbType.DateTime)
        workParam.Direction = ParameterDirection.Input
        workParam.Value = idtChange
        daEIDEmp.SelectCommand.Parameters.Add(workParam)

        'run the stored procedure and fill a dataset
        daEIDEmp.Fill(dsEmp1.t_Emp.DataSet, "sp_EmpByEID")
        'daEIDEmp.Fill(dtEmp, "sp_EmpByEID")

        'close the connection
        'conn.Close()

        Return dsEmp1

    End Function


Then, the page from which this function was called:



        DsEmp2.Merge(ws.UpdateEIDEmp(iEID, iLName, iFName, iJob, iSuper, _
        iPhone, iPID, iEndda, iBegda, iuserChange, idtChange))
        DsEmp2.AcceptChanges()



Running debugger, I find that there are 2 tables in the dataset, dsEmp1, generated in the .asmx page. Then, after the merge statement in the calling page, there are 2 tables in the dataset, dsEmp2, when before the merge, there was only one. BTW, they are both copies of the same dataset, dsEmp.

How can I force the dataset in the .asmx into the proper table?

Joe
Reply By: jpitzer Reply Date: 1/9/2004 1:46:00 PM
Nevermind. I found the problem. I was creating another table when I called the "Fill":
daEIDEmp.Fill(dsEmp1, "sp_EmpByEID")
The schema name for the table was "t_Emp". I had used the name of the stored procedure.

Thanks anyway.
Joe

Go to topic 8379

Return to index page 972
Return to index page 971
Return to index page 970
Return to index page 969
Return to index page 968
Return to index page 967
Return to index page 966
Return to index page 965
Return to index page 964
Return to index page 963