troubleshooting Question

Urgent! currency mananger databinding problem -- adding a new record but the last record viewed being overwritten

Avatar of jinghuei
jinghueiFlag for Taiwan, Province of China asked on
Visual Basic.NET
12 Comments1 Solution239 ViewsLast Modified:
Hi, expert:

I use dataset with 2 dataadapters, and use currency manager (cm) to bind the "sale" table.

My problem is when I use the cm to add a new record, I just got the last record been overwritten.

Can any one check for me? Thanks in advance.

#code for setting the sqldataadapter、cm、dataset---------------------------------------------
  Select Case FormLogin.User_Clevel
            Case "S"
                daDept = New SqlDataAdapter("select * from dept", sqlconnection1)
            Case "D"
                daDept = New SqlDataAdapter("select * from dept where cno = " & FormLogin.inputId, sqlconnection1)
        End Select
        daDept.Fill(dsDeptSaleR, "dept")
        Dim cbd As New SqlCommandBuilder(daDept)
        cboDeptNameSearch.DataSource = dsDeptSaleR.Tables("dept")
        cboDeptName.DisplayMember = dsDeptSaleR.Tables("dept").Columns("name").ToString
        cboDeptName.ValueMember = dsDeptSaleR.Tables("dept").Columns("cno").ToString

 Select Case FormLogin.User_Clevel
            Case "S"
                If cbodeptnameSearch.SelectedValue = 0 Then
                    daSaleR = New SqlDataAdapter("select * from Sale where wname like '" & cboWarrantName.Text.Trim.ToString & "' + '%'", sqlconnection1)
                    daSaleR = New SqlDataAdapter("select * from Sale where cno = " & cbodeptnameSearch.SelectedValue & " and wname like '" & cboWarrantName.Text.Trim.ToString & "' + '%'", sqlconnection1)
                End If

            Case "D"
                    daSaleR = New SqlDataAdapter("select * from Sale where cno = " & FormLogin.inputId & " and wname like '" & cboWarrantName.Text.Trim.ToString & "' + '%'", sqlconnection1)
        End Select

        daSaleR.Fill(dsDeptSaleR, "sale")

        Dim cbs As New SqlCommandBuilder(daSaleR)

        cm = Me.BindingContext(dsDeptSaleR, "sale")
txtWarrantName.DataBindings.Add(New Binding("text", dsDeptSaleR, "sale.wname"))
        cbodeptname.DataBindings.Add(New Binding("datasource", dsDeptSaleR, "dept"))
        cbodeptname.DataSource = dsDeptSaleR.Tables("dept")
        cbodeptname.DisplayMember = dsDeptSaleR.Tables("dept").Columns("name").ToString
        cbodeptname.ValueMember = dsDeptSaleR.Tables("dept").Columns("cno").ToString
        cbodeptname.DataBindings.Add(New Binding("selectedvalue", dsDeptSaleR, "sale.cno"))

        txtSerialNo.DataBindings.Add(New Binding("text", dsDeptSaleR, "sale.serialno"))
        txtID.DataBindings.Add(New Binding("text", dsDeptSaleR, ""))
        txtSno.DataBindings.Add(New Binding("text", dsDeptSaleR, "sale.sno"))
        txtBuyUnit.DataBindings.Add(New Binding("text", dsDeptSaleR, "sale.buyunit"))
        txtTotal.DataBindings.Add(New Binding("text", dsDeptSaleR, ""))
        dptPayDate.DataBindings.Add(New Binding("value", dsDeptSaleR, "sale.paydate"))
        cboHSource.DataBindings.Add(New Binding("text", dsDeptSaleR, "sale.item"))

#toolbar fuctions-----------------------------------------------------------------------
Private Sub myToolBar_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs)
      Dim posBeforeCancel As Integer = 0
        Select Case MyToolBar.Buttons.IndexOf(e.Button)
          Case 1
                If cm.Position <> 0 Then
                    cm.Position -= 1
                End If
            Case 2
                If cm.Position < cm.Count - 1 Then
                    cm.Position += 1
                End If

            Case 3
               cm.Position = cm.Count - 1
#code for adding record-----------------------------------------------------------
            Case 4
            Case 5
                If (cm.Count > 0) Then
                    posBeforeCancel = cm.Position
                End If
            Case 6
              If (cm.Position + 1 = cm.Count) Then
                    posBeforeCancel = cm.Position + 1
                    posBeforeCancel = cm.Position
                End If


                cm.Position = posBeforeCancel
 #code for updating record--------------------------------------------------------------------------            
            Case 7

                If (dsDeptSaleR.HasChanges) Then
                    Dim dsChanges As DataSet = dsDeptSaleR.GetChanges()
                    daSaleR.Update(dsChanges, "Sale")
                End If

            Case 8

        End Select

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 12 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros