954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

combobox or textbox should fill on selected value of other combo in vb.net.

0
By kau14 on Jan 21st, 2012 1:13 pm

Hi

first of all am new to progarmming. Am using using combo box control in vb.net


combo box getting filled properly

Public Sub new_entry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cn As New SqlClient.SqlConnection("Data Source=KAU-4A76A124FB9;Initial Catalog=SRRY;Integrated Security=True")
cn.Open()
Dim adp As New SqlDataAdapter("select * from Bank_Details order by (bank_id)", cn)
Dim ds As New DataSet
adp.Fill(ds)
With Combo_Bank_1
.DataSource = ds.Tables(0)
.DisplayMember = "Bank_Name"
.ValueMember = "Bank_Id"
.SelectedIndex = 0
End With
cn.Close()
End Sub

But now i want on selected value of Combo_Bank_1 another combo box should get filled

i have tried this

Private Sub Combo_Bank_1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Combo_Bank_1.SelectedIndexChanged
Dim cn As New SqlClient.SqlConnection("Data Source=KAU-4A76A124FB9;Initial Catalog=SRRY;Integrated Security=True")

Dim adp1 As New SqlDataAdapter("select Bank_Name from Bank_Details where bank_id='" & Combo_Bank_1.SelectedValue & "'", cn)

Dim ds1 As New DataSet

adp1.Fill(ds1)

txt_PName.Text = ds1.Tables(0).Rows(0).Item(0)

If Combo_Bank_1.SelectedValue = 0 Then
MsgBox("select")
Else
txt_PName.Text = ds1.Tables(0).Rows(0).Item(0)
End If

cn.Close()
End Sub


am getting error

Operator '&' is not defined for string "select Bank_Name from Bank_Detai" and type 'DataRowView'.

i have tried converting it to string , also to int
am able to display the value of selectd index, selected value but not able to passed in sql query


if i entered value directly i.e

Dim adp1 As New SqlDataAdapter("select Bank_Name from Bank_Details where bank_id=1", cn)

Its working. but not able to passed the value from Combo_Bank_1


Plz help


thanks

Kaustubh

Hi

first of all am new to progarmming. Am using using combo box control in vb.net


combo box getting filled properly

  Public Sub new_entry_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim cn As New SqlClient.SqlConnection("Data Source=KAU-4A76A124FB9;Initial Catalog=SRRY;Integrated Security=True")
        cn.Open()
        Dim adp As New SqlDataAdapter("select * from Bank_Details order by (bank_id)", cn)
        Dim ds As New DataSet
        adp.Fill(ds)
        With Combo_Bank_1
            .DataSource = ds.Tables(0)
            .DisplayMember = "Bank_Name"
            .ValueMember = "Bank_Id"
            .SelectedIndex = 0
        End With
        cn.Close()
    End Sub

But now i want on selected value of Combo_Bank_1 another combo box should get filled

i have tried this

Private Sub Combo_Bank_1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Combo_Bank_1.SelectedIndexChanged
        Dim cn As New SqlClient.SqlConnection("Data Source=KAU-4A76A124FB9;Initial Catalog=SRRY;Integrated Security=True")

        Dim adp1 As New SqlDataAdapter("select Bank_Name from Bank_Details where bank_id='" & Combo_Bank_1.SelectedValue & "'", cn)

        Dim ds1 As New DataSet

        adp1.Fill(ds1)

        txt_PName.Text = ds1.Tables(0).Rows(0).Item(0)

        If Combo_Bank_1.SelectedValue = 0 Then
            MsgBox("select")
        Else
            txt_PName.Text = ds1.Tables(0).Rows(0).Item(0)
        End If

        cn.Close()
    End Sub


am getting error

Operator '&' is not defined for string "select Bank_Name from Bank_Detai" and type 'DataRowView'.

i have tried  converting it to string , also to int 
am able to display the value of selectd index, selected value but not able to passed in sql query


if i entered value directly i.e

Dim adp1 As New SqlDataAdapter("select Bank_Name from Bank_Details where bank_id=1", cn)

Its working. but not able to passed the value from Combo_Bank_1


Plz help


thanks 

Kaustubh

Hi,
First of all in line 30 I think you should change to '" & Combo_Bank_1.SelectedIndex.ToString & "'
Try this and tell us..

skran
Light Poster
43 posts since Nov 2011
Reputation Points: 19
Solved Threads: 2
 
Hi, First of all in line 30 I think you should change to '" & Combo_Bank_1.SelectedIndex.ToString & "' Try this and tell us..

HI

Now am getting error

There is no row at position 0.

kau14
Newbie Poster
15 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

Ok, look what I have done.. I had also cascading combobox..

Dim PostcodeDA As New SqlDataAdapter()
        Dim DSpostcode As New AMRtoSQLDataSet
        PostcodeDA.SelectCommand = New SqlCommand()
        PostcodeDA.SelectCommand.Connection = conn
        PostcodeDA.SelectCommand.CommandText = "SELECT Postcode,StreetName_LCL FROM T_MUNICIPALITY_STREETS WHERE StreetName_LCL= '" & cboStreetName1.SelectedIndex.ToString & "'"
        PostcodeDA.Fill(DSpostcode, "PostcodeTable")
        cboPostcode.DataSource = DSpostcode.Tables("PostcodeTable")
        cboPostcode.DisplayMember = "Postcode"
        cboPostcode.ValueMember = "Postcode"
        cboPostcode.SelectedValue = 0

The cboPostcode is depends on cboStreetName choice...

skran
Light Poster
43 posts since Nov 2011
Reputation Points: 19
Solved Threads: 2
 
Hi, First of all in line 30 I think you should change to '" & Combo_Bank_1.SelectedIndex.ToString & "' Try this and tell us..

Hi

with

Combo_Bank_1.SelectedIndex.ToString

its giving me the 1 value before selected value

while i want serach

Combo_Bank_1.SelectedItem.ToString

Its giving me the error

Conversion failed when converting the varchar value 'System.Data.DataRowView' to data type int.

kau14
Newbie Poster
15 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

Skaran

thanks for u r reply

its working with selected index property but its was giving one earlier value so i have added

--select-- value in table at 0 position

now the code is working fine.

Thanks

kaustubh

kau14
Newbie Poster
15 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

I'm glad I could help! :)

skran
Light Poster
43 posts since Nov 2011
Reputation Points: 19
Solved Threads: 2
 

And if it's easy for you please mark the problem as solved. Thanks!

skran
Light Poster
43 posts since Nov 2011
Reputation Points: 19
Solved Threads: 2
 

how to marked as solve???

kau14
Newbie Poster
15 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

Down the page has a question "Has this thread been answered?". You have to choose
" Mark this Thread as Solved "

skran
Light Poster
43 posts since Nov 2011
Reputation Points: 19
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You