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
Iftikar HussainPosted Jul 25, 2013, 10:23 PM
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
Aman JenPosted Jul 25, 2013, 2:04 PM
if I use While loop then it shows last Record...only...on any selection
Iftikar HussainPosted Jul 25, 2013, 1:34 PM
DP2.SelectedItem.Value
DP1.SelectedItem.Value
Regards,
Iftikar
Senthil KiumarPosted Jul 25, 2013, 1:32 PM
While(dr.read())
tb1.Text = dr.Item("Loan_type").ToString
tb2.Text = dr.Item("Curt_EMI").ToString
End While
Aman JenPosted Jul 25, 2013, 1:30 PM
showing this error on same line
.webcontrols.listitem' cannot be converted to system.data.datarowview
Iftikar HussainPosted Jul 25, 2013, 1:15 PM
Regards,
Iftikar
Aman JenPosted Jul 25, 2013, 1:05 PM
Did same , but showing trycast error
Sanjeeb LenkaPosted Jul 25, 2013, 1:01 PM
Dim id As Object = dataRow.Row.ItemArray(0)
Aman JenPosted Jul 25, 2013, 12:59 PM
can you please convert that in vb.net
DataRowView dataRow = DP2.SelectedItem as DataRowView;
object id = dataRow.Row.ItemArray[0];
Iftikar HussainPosted Jul 25, 2013, 12:46 PM
Regards,
Iftikar
Aman JenPosted Jul 25, 2013, 12:44 PM
Iftikar HussainPosted Jul 25, 2013, 11:53 AM
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 JenPosted Jul 25, 2013, 10:40 AM
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..
Sanjeeb LenkaPosted Jul 25, 2013, 10:20 AM
i am unable to understand your requirement. plz provide clear details.
Aman JenPosted Jul 25, 2013, 9:14 AM
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 LenkaPosted Jul 25, 2013, 8:55 AM
for showing all record try to use gridview .