Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

not able to search the updated record

$
0
0
The code for update button and search button work fine but the search button does not work for a record which is updated.
If I insert a new record and then click search,it works.But,if I update that record and then click search,the record is not dislayed in the textboxes.My code for both update and search is below.

 Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click
        Dim sqlcon As New SqlConnection(My.Settings.Hardware_DatabaseConnectionString)
        sqlcon.Open()
        Dim datestr As String
        Dim sqlcmdsearch As New SqlCommand("SELECT Prd_Type from Product_Table where Prd_Sr_Key_No='" & SrKeyNoTextBox.Text & "'", sqlcon)
        Dim sdrsearch As SqlDataReader

        Dim sqlcmdsearchcust As New SqlCommand("SELECT Product_Table.*,Customer_Table.* from Product_Table inner join (Customer_Table inner join Prd_Cust_Table on Customer_Table.C_Code=Prd_Cust_Table.C_Code) on Product_Table.Prd_Sr_Key_No = Prd_Cust_Table.Prd_Sr_Key_No where Product_Table.Prd_Sr_Key_No='" & SrKeyNoTextBox.Text & "'", sqlcon)
        Dim sdrsearchcust As SqlDataReader

        Dim sqlcmdsearchvend As New SqlCommand("SELECT Product_Table.*,Vendor_Table.* from Product_Table inner join (Vendor_Table inner join Prd_Vend_Table on Vendor_Table.V_Code=Prd_Vend_Table.V_Code) on Product_Table.Prd_Sr_Key_No=Prd_Vend_Table.Prd_Sr_Key_No where Product_table.Prd_Sr_Key_No='" & SrKeyNoTextBox.Text & "'", sqlcon)
        Dim sdrsearchvend As SqlDataReader

        Dim sqlcmdri As New SqlCommand("SELECT * from Product_Table inner join Service_Centre_Table on Product_Table.S_Code=Service_Centre_Table.S_Code where Product_Table.Prd_Sr_Key_No='" & SrKeyNoTextBox.Text & "'", sqlcon)
        Dim sdrri As SqlDataReader

        Dim sqlcmdother As New SqlCommand("SELECT Prd_Name,Prd_Type,Prd_Brand,Prd_Detail,Dte_Stck_In,Brght_By,Note from Product_Table where Prd_Sr_Key_No='" & SrKeyNoTextBox.Text & "'", sqlcon)
        Dim sdrother As SqlDataReader


        sdrsearch = sqlcmdsearch.ExecuteReader()
        If sdrsearch.HasRows Then
            While sdrsearch.Read
                ProductTypeComboBox.Text = sdrsearch.Item("Prd_Type")
            End While
        End If
        sdrsearch.Close()

        If ProductTypeComboBox.Text = "REPAIR(INHOUSE)" Then
            sdrsearchcust = sqlcmdsearchcust.ExecuteReader()
            If sdrsearchcust.HasRows Then
                While sdrsearchcust.Read
                    ProductNameTextBox.Text = sdrsearchcust.Item("Prd_Name")


                    If IsDBNull(sdrsearchcust.Item("Prd_Brand")) Then
                        BrandNameComboBox.Text = ""

                    Else
                        BrandNameComboBox.Text = sdrsearchcust.Item("Prd_Brand")

                    End If

                    ProductTypeComboBox.Text = sdrsearchcust.Item("Prd_Type")


                    If IsDBNull(sdrsearchcust.Item("Prd_Detail")) Then
                        DetailRichTextBox.Text = ""

                    Else
                        DetailRichTextBox.Text = sdrsearchcust.Item("Prd_Detail")

                    End If

                    datestr = sdrsearchcust.Item("Dte_Stck_In")
                    Dim splitstr As String() = datestr.Split("/")
                    ddComboBox.Text = splitstr(0)

                    mmComboBox.Text = splitstr(1)

                    yyyyComboBox.Text = splitstr(2)


                    BroughtByTextBox.Text = sdrsearchcust.Item("Brght_By")


                    If IsDBNull(sdrsearchcust.Item("Note")) Then
                        NoteRichTextBox.Text = ""

                    Else
                        NoteRichTextBox.Text = sdrsearchcust.Item("Note")

                    End If

                    CustomerCodeTextBox.Text = sdrsearchcust.Item("C_Code")

                    CustomerNameTextBox.Text = sdrsearchcust.Item("C_Name")

                    CustomerAddressRichTextBox.Text = sdrsearchcust.Item("C_Address")

                    CustomerContactTextBox.Text = sdrsearchcust.Item("C_Cntct")

                    CustomerContactPersonTextBox.Text = sdrsearchcust.Item("C_Cntct_Prsn")

                End While
            End If
            sdrsearchcust.Close()

            'end of if for repair(inhouse)

        ElseIf ProductTypeComboBox.Text = "PURCHASE" Then
            sdrsearchvend = sqlcmdsearchvend.ExecuteReader()
            If sdrsearchvend.HasRows Then
                While sdrsearchvend.Read
                    ProductNameTextBox.Text = sdrsearchvend.Item("Prd_Name")

                    If IsDBNull(sdrsearchvend.Item("Prd_Brand")) Then
                        BrandNameComboBox.Text = ""

                    Else
                        BrandNameComboBox.Text = sdrsearchvend.Item("Prd_Brand")

                    End If
                    ProductTypeComboBox.Text = sdrsearchvend.Item("Prd_Type")


                    If IsDBNull(sdrsearchvend.Item("Prd_Detail")) Then
                        DetailRichTextBox.Text = ""

                    Else
                        DetailRichTextBox.Text = sdrsearchvend.Item("Prd_Detail")

                    End If

                    datestr = sdrsearchvend.Item("Dte_Stck_In")
                    Dim splitstr As String() = datestr.Split("/")
                    ddComboBox.Text = splitstr(0)

                    mmComboBox.Text = splitstr(1)

                    yyyyComboBox.Text = splitstr(2)



                    BroughtByTextBox.Text = sdrsearchvend.Item("Brght_By")

                    NoteRichTextBox.Text = sdrsearchvend.Item("Note")


                    PurchasePriceTextBox.Text = sdrsearchvend.Item("Prchs_Prce")

                    InvoiceNoTextBox.Text = sdrsearchvend.Item("Invce_No")

                    PurchaseWarrantyTextBox.Text = sdrsearchvend.Item("Prchs_Wrrnty")


                    VendorCodeTextBox.Text = sdrsearchvend.Item("V_Code")

                    VendorNameComboBox.Text = sdrsearchvend.Item("V_Name")

                    VendorAddressRichTextBox.Text = sdrsearchvend.Item("V_Address")

                    VendorContactTextBox.Text = sdrsearchvend.Item("V_Cntct")

                    VendorContactPersonTextBox.Text = sdrsearchvend.Item("V_Cntct_Prsn")

                End While
                sdrsearchvend.Close()
            End If

            'end of if for purchase

        ElseIf ProductTypeComboBox.Text = "REPAIRED(INWARD)" Then
            sdrri = sqlcmdri.ExecuteReader()
            If sdrri.HasRows Then
                While sdrri.Read
                    ProductNameTextBox.Text = sdrri.Item("Prd_Name")

                    BrandNameComboBox.Text = sdrri.Item("Prd_Brand")

                    ProductTypeComboBox.Text = sdrri.Item("Prd_Type")

                    DetailRichTextBox.Text = sdrri.Item("Prd_Detail")

                    datestr = sdrri.Item("Dte_Stck_In")
                    Dim splitstr As String() = datestr.Split("/")
                    ddComboBox.Text = splitstr(0)

                    mmComboBox.Text = splitstr(1)

                    yyyyComboBox.Text = splitstr(2)


                    BroughtByTextBox.Text = sdrri.Item("Brght_By")

                    If IsDBNull(sdrri.Item("Note")) Then
                        NoteRichTextBox.Text = ""
                    Else
                        NoteRichTextBox.Text = sdrri.Item("Note")

                    End If

                    ServiceCentreCodeTextBox.Text = sdrri.Item("S_Code")
                    'ServiceCentreCodeTextBox.ReadOnly = True
                    ServiceCentreNameComboBox.Text = sdrri.Item("S_Name")
                    'ServiceCentreNameComboBox.Enabled = False
                    ServiceCentreAddressRichTextBox.Text = sdrri.Item("S_Address")
                    'ServiceCentreAddressRichTextBox.ReadOnly = True
                    ServiceCentreContactTextBox.Text = sdrri.Item("S_Cntct")
                    'ServiceCentreContactTextBox.ReadOnly = True
                    ServiceCentreContactPersonTextBox.Text = sdrri.Item("S_Cntct_Prsn")
                    'ServiceCentreContactPersonTextBox.ReadOnly = True
                End While
            End If
            sdrri.Close()

            'end of if for repaired(inward)

        ElseIf ProductTypeComboBox.Text = "BUYBACK" Then
            sdrother = sqlcmdother.ExecuteReader()
            If sdrother.HasRows Then
                While sdrother.Read
                    ProductNameTextBox.Text = sdrother.Item("Prd_Name")
                    'ProductNameTextBox.Enabled = False
                    BrandNameComboBox.Text = sdrother.Item("Prd_Brand")
                    'BrandNameComboBox.Enabled = False
                    ProductTypeComboBox.Text = sdrother.Item("Prd_Type")
                    'ProductTypeComboBox.Enabled = False
                    DetailRichTextBox.Text = sdrother.Item("Prd_Detail")
                    'DetailRichTextBox.Enabled = False

                    datestr = sdrother.Item("Dte_Stck_In")
                    Dim splitstr As String() = datestr.Split("/")
                    ddComboBox.Text = splitstr(0)
                    'ddComboBox.Enabled = False
                    mmComboBox.Text = splitstr(1)
                    'mmComboBox.Enabled = False
                    yyyyComboBox.Text = splitstr(2)
                    'yyyyComboBox.Enabled = False

                    BroughtByTextBox.Text = sdrother.Item("Brght_By")
                    'BroughtByTextBox.ReadOnly = True

                    If IsDBNull("Note") Then
                        NoteRichTextBox.Text = ""
                        '   NoteRichTextBox.ReadOnly = True
                    Else
                        NoteRichTextBox.Text = sdrother.Item("Note")
                        '  NoteRichTextBox.ReadOnly = True
                    End If

                End While
            End If
            sdrother.Close()

        ElseIf ProductTypeComboBox.Text = "REPLACED" Then
            sdrother = sqlcmdother.ExecuteReader()
            If sdrother.HasRows Then
                While sdrother.Read
                    ProductNameTextBox.Text = sdrother.Item("Prd_Name")
                    'ProductNameTextBox.Enabled = False
                    BrandNameComboBox.Text = sdrother.Item("Prd_Brand")
                    'BrandNameComboBox.Enabled = False
                    ProductTypeComboBox.Text = sdrother.Item("Prd_Type")
                    'ProductTypeComboBox.Enabled = False
                    DetailRichTextBox.Text = sdrother.Item("Prd_Detail")
                    'DetailRichTextBox.Enabled = False

                    datestr = sdrother.Item("Dte_Stck_In")
                    Dim splitstr As String() = datestr.Split("/")
                    ddComboBox.Text = splitstr(0)
                    'ddComboBox.Enabled = False
                    mmComboBox.Text = splitstr(1)
                    'mmComboBox.Enabled = False
                    yyyyComboBox.Text = splitstr(2)
                    'yyyyComboBox.Enabled = False

                    BroughtByTextBox.Text = sdrother.Item("Brght_By")
                    'BroughtByTextBox.ReadOnly = True
                    If IsDBNull("Note") Then
                        NoteRichTextBox.Text = ""
                        '   NoteRichTextBox.ReadOnly = True
                    Else
                        NoteRichTextBox.Text = sdrother.Item("Note")
                        '  NoteRichTextBox.ReadOnly = True
                    End If
                End While
            End If
            sdrother.Close()

        ElseIf ProductTypeComboBox.Text = "BAD" Then
            sdrother = sqlcmdother.ExecuteReader()
            If sdrother.HasRows Then
                While sdrother.Read
                    ProductNameTextBox.Text = sdrother.Item("Prd_Name")
                    'ProductNameTextBox.ReadOnly = True
                    BrandNameComboBox.Text = sdrother.Item("Prd_Brand")
                    'BrandNameComboBox.Enabled = False
                    ProductTypeComboBox.Text = sdrother.Item("Prd_Type")
                    'ProductTypeComboBox.Enabled = False
                    DetailRichTextBox.Text = sdrother.Item("Prd_Detail")
                    'DetailRichTextBox.ReadOnly = True

                    datestr = sdrother.Item("Dte_Stck_In")
                    Dim splitstr As String() = datestr.Split("/")
                    ddComboBox.Text = splitstr(0)
                    'ddComboBox.Enabled = False
                    mmComboBox.Text = splitstr(1)
                    'mmComboBox.Enabled = False
                    yyyyComboBox.Text = splitstr(2)
                    'yyyyComboBox.Enabled = False

                    BroughtByTextBox.Text = sdrother.Item("Brght_By")
                    'BroughtByTextBox.ReadOnly = True

                    If IsDBNull("Note") Then
                        NoteRichTextBox.Text = ""
                        '   NoteRichTextBox.ReadOnly = True
                    Else
                        NoteRichTextBox.Text = sdrother.Item("Note")
                        '  NoteRichTextBox.ReadOnly = True
                    End If
                End While
            End If
            sdrother.Close()
        Else
            sqlcon.Close()
            MsgBox("Invalid Product Type")
        End If

        'end of if for product type 
    End Sub

    Private Sub UpdateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateButton.Click

        Dim sqlcon As New SqlConnection(My.Settings.Hardware_DatabaseConnectionString)
        sqlcon.Open()
        Dim rowsaffected As Integer

        If ProductTypeComboBox.Text = "PURCHASE" Then

            Dim sqlcmdupdteprchs As New SqlCommand("Update Product_Table set Prd_Name=@prdname,Prd_Brand=@prdbrand,Prd_Type=@prdtype,Prd_Detail=@prddetail,Dte_Stck_In=@dtestckin,Brght_By=@brghtby,Note=@note,Prchs_Prce=@prchsprce,Invce_No=@invceno,Prchs_Wrrnty=@prchswrrnty", sqlcon)

            sqlcmdupdteprchs.Parameters.AddWithValue("@prdname", Trim(ProductNameTextBox.Text))
            sqlcmdupdteprchs.Parameters.AddWithValue("@prdbrand", Trim(BrandNameComboBox.Text))
            sqlcmdupdteprchs.Parameters.AddWithValue("@prdtype", Trim(ProductTypeComboBox.Text))
            sqlcmdupdteprchs.Parameters.AddWithValue("@prddetail", Trim(DetailRichTextBox.Text))
            'sqlcmdupdteprchs.Parameters.AddWithValue("@scode", "")
            sqlcmdupdteprchs.Parameters.AddWithValue("@dtestckin", ddComboBox.Text + "/" + mmComboBox.Text + "/" + yyyyComboBox.Text)
            sqlcmdupdteprchs.Parameters.AddWithValue("@brghtby", Trim(BroughtByTextBox.Text))
            sqlcmdupdteprchs.Parameters.AddWithValue("@note", Trim(NoteRichTextBox.Text))
            sqlcmdupdteprchs.Parameters.AddWithValue("@prchsprce", PurchasePriceTextBox.Text)
            sqlcmdupdteprchs.Parameters.AddWithValue("@invceno", InvoiceNoTextBox.Text)
            sqlcmdupdteprchs.Parameters.AddWithValue("@prchswrrnty", Trim(PurchaseWarrantyTextBox.Text))
            rowsaffected = sqlcmdupdteprchs.ExecuteNonQuery()
        End If
        'end of if for product type = purchase
    End Sub



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>