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

retrieve values from tables having one to many relationship

$
0
0
I am retrieving data from tables with one to many relationship and displaying them inside textboxes.I dont get any error but no data is being displayed in the textboxes.There are two tables Product_Table and Service_Centre_Table.Produtct_Table contains S_Code which is primary key of Service_Centre_Table.Record should be dispalyed depending on the Prd_Sr_Key_No which is primary key of Product_Table entered in the Sr.Key.No textbox.
Following is my code:
 Dim sqlcon As New SqlConnection(My.Settings.Hardware_DatabaseConnectionString)
        sqlcon.Open()
        Dim datestr As String
 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 Prd_Sr_Key_No='" & SrKeyNoTextBox.Text & "'", sqlcon)
        Dim sdrri As SqlDataReader

        sdrsearch = sqlcmdsearch.ExecuteReader()
        If sdrsearch.HasRows Then
            While sdrsearch.Read
                ProductTypeComboBox.Text = sdrsearch.Item("Prd_Type")
            End While
        End If
        sdrsearch.Close()
 ElseIf ProductTypeComboBox.Text = "REPAIR(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")
                        NoteRichTextBox.Text = sdrri.Item("Note")

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


Viewing all articles
Browse latest Browse all 51036

Trending Articles



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