Hi,
I have 2 DropDownlistBox in Front end
DP1
DP2
2 TextBoxes, Which Should Show Data based on Selected Item from DP2 on Button Click event
2 SqlDb Table Joined by common Column Loan_code,
Bank1
Bank2
DP2 shows Item Based on Item selected From DP1..till here its working fine, But, show just first record...
Below is my code ...
Public Sub ShowData()
cmd.Connection = cn
cmd.CommandText = "Select Bank1.Loan_type , Bank2.Curt_EMI FROM Bank1 INNER JOIN Bank2 ON Bank1.Loan_code = Bank2.Loan_code"
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()
If dr.HasRows Then
dr.Read()
tb1.Text = dr.Item("Loan_type").ToString
tb2.Text = dr.Item("Curt_EMI").ToString
End If
End Sub
Join query is working fine in sqlDB Environment, But in frontend it is fetching just one record
Plz Help
Loading

Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 25, 2013, 4:55 AM EDT
for showing all record try to use gridview .
Aman Jen136 reputationPosted Jul 25, 2013, 5:14 AM EDT
I have Used same method for 1 Dropdownlist Box And textboxes , which show records based on selected item from DropDown..now its just another Dropdownlist Box which show items based on 1st one...and it should show records according to item selected from this second Dropdownlist here 2 tables are combined with common column, but it is show only first record....
i guess thers is a problem in my sql query..
plz have luk
Thnx
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 25, 2013, 6:20 AM EDT
i am unable to understand your requirement. plz provide clear details.
Aman Jen136 reputationPosted Jul 25, 2013, 6:40 AM EDT
I have 2 DropDownList Box, 2 TextBoxes, And 1 Button.
1)When I Select Item From DropDownList-1 ,Based on this DropDownList-2 gets Populated.
2)When I Select Item From DropDownList-2, 2 Textboxes fetches records based on item selected from DropDownList -2 on button_click event
Here, I have 2 two tables in backend which are joined by common column, from these tables I am fetching records.
Problem is I am just getting 1st record from these joined tables.
Below is the code:
Public Sub ShowData()
cmd.Connection = cn
cmd.CommandText = "Select Bank1.Loan_type , Bank2.Curt_EMI FROM Bank1 INNER JOIN Bank2 ON Bank1.Loan_code = Bank2.Loan_code"
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()
If dr.HasRows Then
dr.Read()
tb1.Text = dr.Item("Loan_type").ToString
tb2.Text = dr.Item("Curt_EMI").ToString
End If
End Sub
I have tried below queries also but not working :
'cmd.CommandText = "Select Bank1.Loan_type , Bank2.Curt_EMI FROM Bank1 INNER JOIN Bank2 ON Bank1.Loan_code = Bank2.Loan_code Where Bank1.Bor_Name = '" & DP2.SelectedItem.Value & "'"
cmd.CommandText = "Select Bank1.Loan_type , Bank2.Curt_EMI FROM Bank1 INNER JOIN Bank2 ON Bank1.Loan_code = Bank2.Loan_code Where Bank1.Bor_Name = @Bor_Name"
cmd.Parameters.AddWithValue("@Bor_Name", DP2.SelectedItem.Value)
I hope I am Clear with question...
Plz help
Thnx..
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 25, 2013, 7:53 AM EDT
Your second dropdown is not getting the selected value, therefore it is not working.
Can you share how you are binding the second drop down?
try like this
cmd.CommandText = "Select Bank1.Loan_type , Bank2.Curt_EMI FROM Bank1 INNER JOIN Bank2 ON Bank1.Loan_code = Bank2.Loan_code Where Bank1.Bor_Name = @Bor_Name"
cmd.Parameters.AddWithValue("@Bor_Name", id.ToString())
Regards,
Iftikar
Aman Jen136 reputationPosted Jul 25, 2013, 8:44 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 25, 2013, 8:46 AM EDT
Regards,
Iftikar
Aman Jen136 reputationPosted Jul 25, 2013, 8:59 AM EDT
can you please convert that in vb.net
DataRowView dataRow = DP2.SelectedItem as DataRowView;
object id = dataRow.Row.ItemArray[0];
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 25, 2013, 9:01 AM EDT
Dim id As Object = dataRow.Row.ItemArray(0)
Aman Jen136 reputationPosted Jul 25, 2013, 9:05 AM EDT
Did same , but showing trycast error
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 25, 2013, 9:15 AM EDT
Dim dataRow As DataRowView = DirectCast(DP2.SelectedItem, DataRowView) Dim id As Object = dataRow.Row.ItemArray(0)Regards,
Iftikar
Aman Jen136 reputationPosted Jul 25, 2013, 9:30 AM EDT
showing this error on same line
.webcontrols.listitem' cannot be converted to system.data.datarowview
Senthil Kiumar43 reputationPosted Jul 25, 2013, 9:32 AM EDT
While(dr.read())
tb1.Text = dr.Item("Loan_type").ToString
tb2.Text = dr.Item("Curt_EMI").ToString
End While
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 25, 2013, 9:34 AM EDT
DP2.SelectedItem.Value
DP1.SelectedItem.Value
Regards,
Iftikar
Aman Jen136 reputationPosted Jul 25, 2013, 10:04 AM EDT
if I use While loop then it shows last Record...only...on any selection
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 25, 2013, 6:23 PM EDT
Select Bank1.Loan_type , Bank2.Curt_EMI FROM Bank1 INNER JOIN Bank2 ON Bank1.Loan_code = Bank2.Loan_code Where Bank1.Bor_Name = @Bor_Name
Regards,
Iftikar