954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how can i display data in textbox from choosen dropdown menu?

im a beginner in vb.net.im developing for myproject in windows application.my ques:how can i display data in textbox from choosen dropdown menu?user choose a item in combobox,then after click a button the meaning of data appear in textbox..i need some help..tq in advance

lacaroix
Newbie Poster
18 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

Do you really need to click that button? If so, then double click your button and past following code in it:

TextBox1.Text = ComboBox1.Text


otherwise you can double click your combobox a paste same code in there instead. That will save you extra click (won't need to click button to see combobox selection in textbox as it will appear automatically).

Hope this helps.

P.S. of course don't forget to modify textbox and combobox names if they are different.

leokuz
Light Poster
36 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

okay.i try to run..there's an erorr about connection string..
"An unhandled exception of type 'System.ArgumentException' occurred in System.Data.SqlClient.dll

Additional information: Unknown connection option in connection string: driver."

im not veru sure about the coding to connection of database..any advice?tq~

lacaroix
Newbie Poster
18 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        textbox1.Text = ComboBox1.SelectedItem
End Sub
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

oh thanks..sorry for the late reply..neway i tried.i think there might haf some problems wif my connection string..its stil error..so mybe i need to figure it out wat happen act..

lacaroix
Newbie Poster
18 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

what database that u using on?sqlserver or access?

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

im using sqlserver..act im not sure wat my prob is..here my coding for click button..afta i run the application there the error sed

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.SqlClient.dll

Additional information: The ConnectionString property has not been initialized.

here my coding...

Dim connectionString As String = "Driver={MySQL};SERVER=MUBINZ;DATABASE=japanese;"
Dim conManager As String = ""
Dim com As New SqlCommand
Dim conn As New SqlConnection'open connection
Dim text As String = TextBox1.Text
Dim list As String = ComboBox1.SelectedValue
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim dr As SqlDataReader
Dim sql As String


conn.Open()

list = Me.ComboBox1.Items("Good morning") = 0
sql = "select translation_japan from table_greeting where greet_id = & Good morning.selectedvalue"
com.CommandText = sql
conn.ConnectionString = connectionString
com.Connection = conn
dr = com.ExecuteReader()

While dr.Read
text = dr.GetValue(0)
End While

TextBox1.Text = text
conn.Close()

End Sub

lacaroix
Newbie Poster
18 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

sorry..here my coding...the error stil the same..there an arrow shoe at the
conn.Open()
thanks you in advanced..

Dim connectionString As String = "Driver={MySQL};SERVER=MUBINZ;DATABASE=japanese;"
Dim conManager As String = ""
Dim com As New SqlCommand
Dim conn As New SqlConnection'open connection
Dim text As String = TextBox1.Text
Dim temp As String = ComboBox1.SelectedItem
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim dr As SqlDataReader
Dim sql As String


conn.Open()

temp = ComboBox1.SelectedItem
sql = "select translation_japan from table_greeting where greet_id = '" & temp & "'"
com.CommandText = sql
conn.ConnectionString = connectionString
com.Connection = conn
dr = com.ExecuteReader()

While dr.Read
text = dr.GetValue(0)
End While

TextBox1.Text = text
conn.Close()

End Sub

lacaroix
Newbie Poster
18 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

this following code to read data and display on combo box, u just put on event like "form load":

Public Function GetConnect()
        Dim conn As SqlConnection
        conn = New SqlConnection("server = jery;database = VBtoC#;Trusted_Connection = yes")
        Return conn
End Function


Private Sub ReadData()
        Dim i As Integer
        Dim cmdStudent As New SqlCommand
        Dim daStudent As New SqlDataAdapter
        Dim dsStudent As New DataSet
        Dim dtStudent As New DataTable
        Dim conn As SqlConnection

        conn = GetConnect()
        Try

            cmdStudent = conn.CreateCommand
            cmdStudent.CommandText = "SELECT * FROM Student"
            daStudent.SelectCommand = cmdStudent
            daStudent.Fill(dsStudent, "Student") ' Table Name
            dtStudent = dsStudent.Tables("Student") 'Table Name
            For i = 0 To dtStudent.Rows.Count - 1
                cmbNis.Items.Add(dtStudent.Rows(i).Item(0))
            Next

        Catch ex As Exception
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Connection Error !!")
        End Try
	conn.Close()
End Sub

Hope this helps..

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

the code will dispay on the combo box rite?
nway mine is select frm the combo box(a japanese word)and displaying in text box which the textbox(english word) will retrieved the data form the database...its sumthing like a dictionary but its simpler than dictionry..
sorry for the trouble but im a bit blurr in tis coding...thanks in advance..

lacaroix
Newbie Poster
18 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

yes, data will display on combo box. in my code id student will display on combo box.

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

i still cant get it.anyway any idea of coding of i just let user choose the item frm combo box then retrived the data from databse and view it.

lacaroix
Newbie Poster
18 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

so combo box item is not retrived from database??
let user choose the item frm combo box then retrived the data from databse and view it.
what was retrived from database?and what to viewed?
how about your database table?

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

ok,the interface 1:combobox 2:textbox(translation).
mine is like in the combobox(dropdown menu) are list of the english words(word_id).user can chose one of the words then after clicking a translate button the meaning of the words will appear in the textbox,which here the data retrieved frm db(word_translate_.and also viewed in textbox.
databse table:table_word
choosen item=word_id
textbox=word_translate

and im also having a problem on connection string.the eror sed "connection string is not initialized."

lacaroix
Newbie Poster
18 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

i have read your other thread. i guest you do this in smart device, right?
i never do this in smart device...

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

thanks for the advice and the codes =)

lacaroix
Newbie Poster
18 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

maybe missing reference :
Click Project menu and click Add Reference.

Microsoft.WindowsCE.Forms
System.Data.Common
System.Data.SqlServerCE
System.Windows.Forms

Set the references then we will import SqlServerCE namespace.

for more clearly see this link

Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 
im a beginner in vb.net.im developing for myproject in windows application.my ques:how can i display data in textbox from choosen dropdown menu?user choose a item in combobox,then after click a button the meaning of data appear in textbox..i need some help..tq in advance

Ans : - You can set the 'Tooltip text' property of the menu to the description. Then, you can set the text property of the textbox to the tooltip text property.
something like this -

Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
txtSearchName.Text = Me.OpenToolStripMenuItem.ToolTipText
End Sub

Thanks & Regards,
Shilp

shilp
Newbie Poster
6 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

Ans : -
You have to set the tooltip text property of the menu. Then , set this text property to the text property of the text box.

something like this -

txtSearchName.text = Me.OpenToolStripMenuItem.TooltipText

Thanks & Regards,
Shilp

im a beginner in vb.net.im developing for myproject in windows application.my ques:how can i display data in textbox from choosen dropdown menu?user choose a item in combobox,then after click a button the meaning of data appear in textbox..i need some help..tq in advance
shilp
Newbie Poster
6 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

hi guys,,
i'm trying to figure out how can i display data from database to textbox..i'm using vb 2008 and mySQL database..

heres my code..

Private Sub Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Search.Click
        check_mem_id = "SELECT Membership_ID FROM account WHERE Membership_ID=" & SearchTxt.Text
        check_mem_id2 = "SELECT First Name, MI, LastName, Address, Contact_No, Gender, Birthdate, DateReg, RegFor, Membership_ID, Password FROM account WHERE Membership_ID=" & SearchTxt.Text
        MyConnString = "datasource=localhost;username=root;password=root;database=salaas"
        MyConnection = New MySqlConnection(MyConnString)
        Try
            MyConnection.Open()

            Dim FirstName As Object
            Dim last_name As Object
            Dim M_I As String
            Dim adrs As String
            Dim cont_no As String
            Dim sex As String
            Dim bdate2 As String
            Dim dateR As String
            Dim regF As String
            Dim mem_ID As String
            Dim pw As String
            Dim account As String


            Dim reader As MySqlDataReader
            Dim reader2 As MySqlDataReader
            da2.SelectCommand = New MySqlCommand(check_mem_id, MyConnection)
            reader = da2.SelectCommand.ExecuteReader


            'check kung nag eexist ung ID

            If reader.Read() = True Then
                MessageBox.Show("Valid Membership ID!")
                Fname.Enabled = True
                Lname.Enabled = True
                MI.Enabled = True
                address.Enabled = True
                ContactNo.Enabled = True
                Gender.Enabled = True
                BDate.Enabled = True
                DateReg.Enabled = True
                RegFor.Enabled = True
                MembershipID.Enabled = True
                PasswordTxt.Enabled = True

                'MyConnection.Close()

                'MyConnection.Open()

               
                While reader.Read()
                    account = reader.Item("account")

                    FirstName = reader.Item("First Name")
                    last_name = reader.Item("LastName")
                    M_I = reader.Item("MI")
                    adrs = reader.Item("Address")
                    cont_no = reader.Item("Contact_No")
                    sex = reader.Item("Gender")
                    bdate2 = reader.Item("Birthdate")
                    dateR = reader.Item("DateReg")
                    regF = reader.Item("RegFor")
                    mem_ID = reader.Item("Membership_ID")
                    pw = reader.Item("Password")

                    Fname.Text = FirstName
                    Lname.Text = last_name
                    MI.Text = M_I
                    address.Text = adrs
                    ContactNo.Text = cont_no
                    Gender.Text = sex
                    BDate.Text = bdate2
                    DateReg.Text = dateR
                    RegFor.Text = regF
                    MembershipID.Text = mem_ID
                    PasswordTxt.Text = pw

                    da3.SelectCommand = New MySqlCommand(check_mem_id2, MyConnection)
                    reader2 = da3.SelectCommand.ExecuteReader

                End While


            Else
                MessageBox.Show("Invalid Membership ID!")
                SearchTxt.Text = ""

            End If
        Catch ex As Common.DbException
            MsgBox(ex.ToString)
        Finally
            MyConnection.Close()
        End Try
    End Sub
dustinsierra
Newbie Poster
2 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You