Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Joined Tables

Status
Not open for further replies.

glewis1636

Programmer
Apr 26, 2004
39
US
I have a dataadapter that joins two tables with and inner join. Because of this I can't use commandbuilder to build my update, insert, and delete commands. I've built the following update command, but get a dbconcurrency error when the da.update(dataset) is executed. Help.

I know the dataset has changes because I have a messagebox that fires if dataset.haschanges = true.

Code:
 cmdSalesRepUpdate = New SqlCommand("UPDATE SalesRep set ProspectID=@ProspectID, " & _
        "SalesRepID=@SalesRepID, CallBackDate=@CallBackDate, ActionCode=@ActionCode FROM SalesRep INNER JOIN " & _
        "SalesReps on SalesRep.SalesRepID = SalesReps.SalesRepID WHERE CallBackDate = @oldCallBackDate", SqlConnection1)

        Dim parm As SqlParameter

        cmdSalesRepUpdate.Parameters.Add("@ProspectID", SqlDbType.BigInt, 8, "ProspectID")
        cmdSalesRepUpdate.Parameters.Add("@SalesRepID", SqlDbType.Char, 10, "SalesRepID")
        cmdSalesRepUpdate.Parameters.Add("@CallBackDate", SqlDbType.DateTime, 8, "CallBackDate")
        cmdSalesRepUpdate.Parameters.Add("@ActionCode", SqlDbType.Char, 2, "ActionCode")
        parm = cmdSalesRepUpdate.Parameters.Add("@oldCallBackDate", SqlDbType.DateTime, 8, "CallbackDate")
        parm.SourceVersion = DataRowVersion.Original
        daSalesRep.UpdateCommand = cmdSalesRepUpdate
 
salesrepid is key to salesreps repkey is key to salesrep.
 
Additional info-
I just realized that I only get this error if the CallBackDate field in the database is null before I make a change to it.
The textbox is bound using
databind.add("Text",dvSales,"CallBackDate").
 
I found a workaround for this now. Changed update command statement to
" ...WHERE CallBackDate = @oldCallBackDate or @oldCallBackDate is null"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top