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

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.

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~

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        textbox1.Text = ComboBox1.SelectedItem
End Sub

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

what database that u using on?sqlserver or access?

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

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

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

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

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

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.

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?

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

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

thanks for the advice and the codes =)

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

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

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

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

it will search first into the database and then display the content of the database on the specified textbox..the problem is it doest display.thanks guys..

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.