Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
I have some String values in Database, the string values ends with K1,K2,K3,J1,K2,J3
This values I want to display in 6 Textboxs, I'm using below <b>code1:</b>,



1. If Database has K1,K2,J1,J2 , then it should show
    In Textbox1: K1
       TextBox2: K2
       TextBox3: <empty>
       TextBox4: J1
       TextBox5: J2
       TextBox6: <empty>
2. If Database has only J1,J2,J3 Then it should show
    In TextBox1: J1
       TextBox2: J2
       TextBox3: J3
       TextBox4: <empty>
       TextBox5: <empty>
       TextBox6: <empty>
3. If Database has K1,J1 then
    In TextBox1: K1
       TextBox2: <empty>
       TextBox3: <empty>
       TextBox4: J1
       TextBox5: <empty>
       TextBox6: <empty>







AL00CK1
AL00CK2
AL00CK3
AL00CJ1
AL00CJ2
AL00CJ3



<b>Code1:</b>


        If dt.Rows.Count > 0 Then
            Me.EUtran1_txt.Text = dt.Rows(0).Item("EUtranCellFDD_Name")
        Else
            EUtran2_txt.Clear()
        End If

        If dt.Rows.Count > 1 Then
            Me.EUtran2_txt.Text = dt.Rows(1).Item("EUtranCellFDD_Name")
        Else
            EUtran2_txt.Clear()
        End If

        If dt.Rows.Count > 2 Then
            Me.EUtran3_txt.Text = dt.Rows(2).Item("EUtranCellFDD_Name")
        Else
            EUtran3_txt.Clear()
        End If

        If dt.Rows.Count > 3 Then
            Me.EUtran4_txt.Text = dt.Rows(3).Item("EUtranCellFDD_Name")
        Else
            EUtran4_txt.Clear()
        End If

        If dt.Rows.Count > 4 Then
            Me.EUtran5_txt.Text = dt.Rows(4).Item("EUtranCellFDD_Name")
        Else
            EUtran5_txt.Clear()
        End If

        If dt.Rows.Count > 5 Then
            Me.EUtran6_txt.Text = dt.Rows(4).Item("EUtranCellFDD_Name")
        Else
            EUtran6_txt.Clear()
        End If
Posted
Updated 29-Jan-15 23:01pm
v3

1 solution

This is not the best way of doing it,i use a list of strings as an example, and i don't really understand why are you trying to do that. But i think this rough code do what you wants
VB
Dim stringList As New List(Of String)() From { _
    "AL00CK1", _
    "AL00CK3", _
    "AL00CJ1", _
    "AL00CJ2" _
}
For Each s As String In stringList
    If s.EndsWith("J1") Then
        textBox1.Text = s
    End If
    If s.EndsWith("J2") Then
        textBox2.Text = s
    End If
    If s.EndsWith("J3") Then
        textBox3.Text = s
    End If
    If s.EndsWith("K1") Then
        textBox4.Text = s
    End If
    If s.EndsWith("K2") Then
        textBox5.Text = s
    End If
    If s.EndsWith("K3") Then
        textBox6.Text = s

    End If
Next
 
Share this answer
 
Comments
Member 11338695 30-Jan-15 6:17am    
Hi Pikoh

Thank you for your reply, The values you are defined manually

Dim stringList As New List(Of String)() From { _
"AL00CK1", _
"AL00CK3", _
"AL00CJ1", _
"AL00CJ2" _
}

But this values I will get when I do search query as "AL00C" ,
Then search values are ( This are keep on change , but ends with K1,K2,K3,J1,J2,J3)
AL00CK1
AL00CK3
AL00CJ1
AL00CJ2

Dim rs As New OleDb.OleDbDataAdapter("Select eNB_Name, EUtranCellFDD_Name from QA_db where eNB_Name Like '%" & search_box.Text & "%' ", con)
rs.Fill(dt)

Then this values need to assign textboxs.
Pikoh 30-Jan-15 6:48am    
Well,then instead of For Each s As String In stringList, use this:

For Each DataRow dr in dt.Tables(0).Rows
string s=dr("eNB_Name").ToString()
If s.EndsWith("J1") Then
textBox1.Text = s
End If
If s.EndsWith("J2") Then
textBox2.Text = s
End If
If s.EndsWith("J3") Then
textBox3.Text = s
End If
If s.EndsWith("K1") Then
textBox4.Text = s
End If
If s.EndsWith("K2") Then
textBox5.Text = s
End If
If s.EndsWith("K3") Then
textBox6.Text = s

End If
Next
Member 11338695 27-Feb-15 4:15am    
Hi Pikoh

Thank You for the first given solution,

I have one more doubt, before you given values which ends K1,K2,K3 & J1,J2,J3
it is working fine, suppose right now I have L1,L2,L3 & M1,M2,M3

This 4 variables which endswith K1,k2,k3,J1,J2,J3,L1,L2,L3 and M1,M2,M3

will have the probability combination of K&J, K&L, K&M or M&L, M&J, M&K or J&L

this values need to show in textboxs[1-6], The variables combination will not be more than 6.

Please help me on this..

Member 11338695 30-Jan-15 7:14am    
Thank You very much, its working , :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900