Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

i want the answer for this

i already store all data's in sql server. when i select data in combobox the database other values like textbox values will show on appropriate textbox.
Posted
Comments
DamithSL 7-Jun-14 7:06am    
update the question with the code of how you binding combobox.

Use Combobox OnselectedIndexChanged event write the program whatever value you have selected set those value in appropriate in text box.
 
Share this answer
 
You can write your code on ComboBox OnSelectedIndexChanged Event to fill your TextBox with appropriate value. You can write your own reusable function for this. See the below code :
VB
''' <summary>
''' Fille TextBox Based On Value Selected in ComboBox.
''' </summary>
''' <param name="SelectField">Table Column Name To Display In TextBox As String</param>
''' <param name="TableName">Table Name As String</param>
''' <param name="ColumnName">Table Column Name For Where Clause</param>
''' <param name="ComboBoxName">ComboBox Name For Where Clause Condition</param>
''' <param name="SetTextBoxName">TextBox Name To Fill Value</param>
''' <remarks></remarks>
Public Sub FillTextBox(ByVal SelectField As String, ByVal TableName As String, ByVal ColumnName As String, ByVal ComboBoxName As ComboBox, ByVal SetTextBoxName As TextBox)
	Dim _ObjDataAdapter As SqlDataAdapter = New SqlDataAdapter
        _ObjDataAdapter.SelectCommand = New SqlCommand
        _ObjDataAdapter.SelectCommand.Connection = _Connection 'Your SqlConnection Object
        _ObjDataAdapter.SelectCommand.CommandText = "Select " & SelectField & " FROM " & TableName & " WHERE " & ColumnName & "='" & ComboBoxName.Text & "'"
        Try
            _ObjDataReader = _ObjDataAdapter.SelectCommand.ExecuteReader() 'Exectuing query
        Catch ex As System.InvalidOperationException
            MessageBox.Show(ex.ToString)               'Providing Error Message
        End Try
        While _ObjDataReader.Read                      'Reading DataReader Items
            SetTextBoxName.Text = _ObjDataReader.Item(0)'Adding these Items Into ComboBox
        End While
        _ObjDataReader.Close()                             'Closing DataReader Object
        _ObjDataAdapter.SelectCommand = Nothing
End Sub

After that you can call this Function on ComboBox OnSelectedIndexChanged Event
VB
FillTextBox("DisplayColumn", "TableName", "WhereClauseColumn", ComboBox1, TextBox1)

I hope this will help you. :)
 
Share this answer
 

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