Hey i am also facing the same problem.
I have tried this but this is not working.
please help me.

Protected Sub cmbParty_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbParty.SelectedIndexChanged
        myConnection.Open()
        Adpt = New SqlDataAdapter("SELECT * FROM PartyMaster where Id = '" & cmbParty.SelectedIndex & "'", myConnection)
        Adpt.Fill(ExDs)
        For Each row In ExDs.Tables(0).Rows
            cmbParty.Items.Add(row(0))
        Next
        myConnection.Close()
       
        'cmbParty.Items.Add("All")
        If ExDs.HasErrors Then
            lblMessage.Text = "Error while fetching Data."
        Else

            
Here i need to take the data from exds to text boxes. As when we click on combobox we need to show data according to that party in all text box's.

            txtParty.Text = command("PartyName")
            txtParty.Text = partyName(cmbParty.Items.IndexOf(cmbParty.Text))
        End If

Please help me.
send details ....


Hi,
Write This Code In Lost_Focus event of ComboBox:(Conn-> Connection object)

DIm RST As New ADODB.RecordSet
Dim sSQL As String

sSQL = "Select * From MyTable Where RollNo = " & Val(Combo1.Text)
RST.Open sSQL, Conn
If Not RSt.EOF Then
txtName.Text = RST("Name")
txtAdd.Text = RST("Addr")
txtAge.Text = RST("Age")
Else
txtName.Text = ""
txtAdd.Text = ""
txtAge.Text = ""
End If
RST.Close
Set RST=Nothing

REgards
Veena

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

Hello Raviachhwani.

SqlDataAdapter works in CLOSED Connection. So, while working with sqlDataAdapter,
you don't need to open and close the connection.

Now, here's the solution to your problem. (This is my approach of coding)

First while loading data into your combo box, do this way:

-------------------------------------------------------------------------------

Adpt = New SqlDataAdapter("SELECT id,PartyName FROM PartyMaster", myConnection)
dim Dset as new DataSet
Adpt.Fill(Dset)
With cmbParty
   .DisplayMember = "PartyName"
   .ValueMember = "id"
   .DataSource = Dset.Tables(0)
End With

--------------------------------------------------------------------------------

Now, when user clicks the value from the comboBox (cmbParty), its corresponding
data should be dispalyed in the textboxes. Right?
This can be done this way.

-------------------------------------------------------------------------------

Adpt = New SqlDataAdapter("SELECT * FROM PartyMaster where 
      Id = " & cmbParty.SelectedValue & "",  myConnection)
dim Dset2 as new DataSet
Adpt.Fill(Dset2)

txtbox1.text =  Dset2.Tables(0).Rows(0)(0)
txtbox2.text =  Dset2.Tables(0).Rows(0)(1)
txtbox3.text =  Dset2.Tables(0).Rows(0)(2)
.
.
.

--------------------------------------------------------------------------------

Ps: I haven't use exceptional Handling in above code.

This article has been dead for over six months. Start a new discussion instead.