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..

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.

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...

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.

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

commented: please give full source code.... +0

I'm glad I could help! :)

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

how to marked as solve???

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

plz give solved source code .............

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.