none
Problem with bindingsource RRS feed

  • General discussion

  • hi

    i am using bindingsource with Master/Detail for data bindings on to the windows forms. I am facing a little problem but hard to find out where the problem is arising in my coding structure. the problem is that when i save the record to the database the record has been saved but when i navigate the record to previous one and return again to the current saving record the child table data will be disappear from the gridview. And when I close the form and reopen it then there is no problem mean both record (master/detail) are showing on to the form.

    here is my codes

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    
              Try
                    Dim com As New SqlCommand
                    com.Connection = dbcon
                    com.Connection.Open()
                    com.CommandText = "INSERT into Requistion values ('" & txtReceiveID.EditValue & "','" & txtGRNDATE.EditValue & "','" & txtGatePass.EditValue & "','" & txtBiltyNo.EditValue & "','" & txtBiltyDate.EditValue & "','" & txtVehicleNo.EditValue & "','" & txtAccID.Text & "','" & txtSupplierName.Text & "','" & txtPurchaseReqNo.Text & "','" & txtPurchaseReqDate.EditValue & "','" & txtPurchaseOrderNo.EditValue & "','" & txtPurchasOrderDate.EditValue & "','" & txtChallanNo.EditValue & "','" & txtChallanDate.EditValue & "','" & txtInvoiceNo.EditValue & "','" & txtInvoiceDate.EditValue & "','" & txtHOChallanNo.EditValue & "','" & txtHOChallanDate.EditValue & "','" & MainFrom.txtUserStatus.Caption & "')"
                    com.ExecuteNonQuery()
                    Dim i As Integer
                    For i = 0 To GridView1.RowCount - 1                    'If StoreDBDataSet.DataTable1.Rows.Count > 0 Then
    
                        Dim IID As String = StoreDBDataSet.RequisitionDetail.Rows(i).Item("ItemID")
                        Dim IName As String = StoreDBDataSet.RequisitionDetail.Rows(i).Item("ItemName")
                        Dim Unit As String = StoreDBDataSet.RequisitionDetail.Rows(i).Item("Unit")
                        Dim Received As Decimal = StoreDBDataSet.RequisitionDetail.Rows(i).Item("Received")
                        Dim Reject As Decimal = StoreDBDataSet.RequisitionDetail.Rows(i).Item("Reject")
                        Dim Accept As Decimal = StoreDBDataSet.RequisitionDetail.Rows(i).Item("Accept")
                        Dim UPrice As Decimal = StoreDBDataSet.RequisitionDetail.Rows(i).Item("UnitPrice")
                        Dim Amount As Decimal = StoreDBDataSet.RequisitionDetail.Rows(i).Item("Cost")
                        Dim STax As Decimal = StoreDBDataSet.RequisitionDetail.Rows(i).Item("SalesTaxP")
                        Dim STR As Decimal = StoreDBDataSet.RequisitionDetail.Rows(i).Item("SalesTaxR")
                        Dim Total As Decimal = StoreDBDataSet.RequisitionDetail.Rows(i).Item("TotalCost")
    
                        com.CommandText = "Insert into RequisitionDetail (ReceivingID,ItemID,ItemName,Unit,Received,Accept,Reject,UnitPrice,Cost,SalesTaxP,SalesTaxR,TotalCost) values ('" & txtReceiveID.EditValue & "','" & IID & "','" & IName & "','" & Unit & "','" & Received & "','" & Accept & "','" & Reject & "','" & UPrice & "','" & Amount & "','" & STax & "','" & STR & "','" & Total & "')"
                        com.ExecuteNonQuery()
                     Next i
    
                    MsgBox("Data Saved Successfully.", MsgBoxStyle.Information)
                    btnPrint.Enabled = True
                Catch ex As Exception
                    MsgBox(ex.ToString)
                End Try
                Call DisabledFields()
            End If
    
            If ConnectionState.Open Then
                dbcon.Close()
            End If
        End Sub

    Thursday, June 28, 2012 10:12 AM

All replies

  • Hi haqayyum,

    Most likely this is not bound DataGridView or the new recorded is not added through the DataGridView. 

    You need to populate the DataGridView again after the new record saved.

    If there is anything unclear, please let me know.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, June 29, 2012 6:53 AM
    Moderator
  • thanks for your guidance

    I implement but the same problem still arising

    Friday, June 29, 2012 7:20 AM
  • As per my understanding You forgot to bind the datasource agian to the child grid.Please check your DataBid function or code.

    With Thanks and Regards
    Sambath Raj.C
    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you
    Happy Programming!

    Friday, June 29, 2012 1:06 PM
  • thanks for your guidance

    I implement but the same problem still arising

    Hi haqayyum,

    Could you please upload a demo to SkyDrive or show us your current code hare? It hard to detect the issue without the code.

    I need to see the code that you populate the DataGridView and the code that update the database.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, July 2, 2012 9:50 AM
    Moderator
  • I would think after you have done the insert you would add a new row to the BindingSource. In the following example the BindingSource bsCustomers DataSource is a DataTable, cast it as shown and add a new row with the values just placed into the backend database. You will see the row after executing the add new row.

    CType(bsCustomers.DataSource, DataTable).Rows.Add(New Object() {values goes here})


    KSG

    Monday, July 2, 2012 4:55 PM
    Moderator