Click here to Skip to main content
15,851,514 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,,
how to retrieve data to a textbox depending on the value selected from a dropdownlist from sqlDb...


I have Managed code for populating Dropdownlist as below:

Public Sub fildp()

cmd.Connection = cn
cmd.CommandText = "Select * From Acct_Sum"
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
da.Fill(dt)
DPList.DataSource = dt
DPList.DataTextField = "Bor_Name"
DPList.DataValueField = "Loan_code"
DPList.DataBind()
DPList.Items.Insert(0, "Select Loan code")

End Sub

Now, I have multiple textboxes on Form. I want to display data from sqldb based on selected item form Dropdownlist..

Plz help
Thnx
Posted
Comments
[no name] 6-Jul-13 7:00am    
"I want to retrive values in multiple textboxes from columns of sqlDb table on selecteindexchange event of dropdownlist", okay so? What is the actual problem that you are having? So far, you have not asked any kind of a question or described any kind of a real problem.
Aman.Jen 6-Jul-13 7:04am    
cn.Open()
cmd.Connection = cn
cmd.CommandText = "Select * from Acct_Sum"
dr = cmd.ExecuteReader
If dr.HasRows Then
dr.Read()
t1.Text = DPList.SelectedItem.Value(dr.Item("Bor_Name"))
t2.Text = DPList.SelectedItem.Value(dr.Item("coBor_Name"))
t3.Text = DPList.SelectedItem.Value(dr.Item("Loan_type"))
t4.Text = DPList.SelectedItem.Value(dr.Item("Loan_Sanc"))
t5.Text = DPList.SelectedItem.Value(dr.Item("Sanc_Perd"))
t6.Text = DPList.SelectedItem.Value(dr.Item("TotalLoan_Disb"))
t7.Text = DPList.SelectedItem.Value(dr.Item("Curt_EMI"))
t8.Text = DPList.SelectedItem.Value(dr.Item("Curt_ROI"))
t9.Text = DPList.SelectedItem.Value(dr.Item("Prinp_Out"))
t10.Text = DPList.SelectedItem.Value(dr.Item("EMI_OVdue"))
End If
cn.Close()


showing error string cannot be converted to integer value

1 solution

VB
DPList_onselectedChanged()
{
textbox1.text = DPList.selecteditem.tostring();
}
 
Share this answer
 
Comments
Aman.Jen 6-Jul-13 6:48am    
nope not working ...I want to retrive values in multiple textboxes from columns of sqlDb table on selecteindexchange event of dropdownlist...
Aman.Jen 6-Jul-13 9:27am    
Plz see the code....even this not working...Dont know wat is issue....not showing any error but neither working


Public Sub bindat()
cmd.Connection = cn
Dim id As String = DPList.SelectedItem.Value

cmd.CommandText = "Select Bor_Name,coBor_Name,Loan_type,Loan_Sanc,Sanc_Perd,TotalLoan_Disb,Curt_EMI Curt_ROI,Prinp_Out,EMI_OVdue from Acct_Sum where Bor_Name = '" & DPList.SelectedItem.Value & "'"

cmd.CommandText = "Select Bor_Name,coBor_Name,Loan_type,Loan_Sanc,Sanc_Perd,TotalLoan_Disb,Curt_EMI Curt_ROI,Prinp_Out,EMI_OVdue from Acct_Sum where Bor_Name ='" & id & "'"
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable
cmd.Parameters.AddWithValue("id", DPList.SelectedItem.Value)
da.Fill(dt)

If (dt.Rows.Count > 0) Then
t1.Text = dt.Rows(0)("Bor_Name").ToString()
t2.Text = dt.Rows(0)("coBor_Name").ToString()
t3.Text = dt.Rows(0)("Loan_type").ToString()
t4.Text = dt.Rows(0)("Loan_Sanc").ToString()
t5.Text = dt.Rows(0)("Sanc_Perd").ToString()
t6.Text = dt.Rows(0)("TotalLoan_Disb").ToString()
t7.Text = dt.Rows(0)("Curt_EMI").ToString()
t8.Text = dt.Rows(0)("Curt_ROI").ToString()
t9.Text = dt.Rows(0)("Prinp_Out").ToString()
t10.Text = dt.Rows(0)("EMI_OVdue").ToString()
End If
End Sub
Nirav Prabtani 8-Jul-13 2:01am    
Try this,,,,:)

t1.Text=dt.Rows(0).Item("Bor_Name").ToString

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