Hi guys

Im trying to save a combobox selected item to my database but i cant get it working, it saves "user" instead of the username that is stored in the combobox, any suggestions? here's a snippett

            '----------------Sends the message-------------------------------------------------------------------
            MysqlConn.Open() ' opening the connection to the DB
            Dim query As String
            Dim thanks As String = "Thanks "
            Dim thankUser As String = cboUsers.SelectedItem.ToString() 'was originally DisplayMember.tostring
            Dim ThankYou As String = thanks + thankUser

            query = "insert into dojodb.chats (Sender, Message) values ('" & lblUser.Text & "','" & ThankYou & "')"
            command = New MySqlCommand(query, MysqlConn)
            reader = command.ExecuteReader 'executes the command and reads data from db
            '-----------------End send--------------------------------------------------------------------------

Recommended Answers

All 4 Replies

You have a databound combobox, right? Use




Hey thanks for your reply!

I have the combobox populated on formload

        Dim da As New MySqlDataAdapter("select UserId, User from dojodb.userinfo where UserGroup <> 'Mentor' and (UserID <> '" & LoggedInUserID & "')", con)
        Dim table As New DataTable()

        cboUsers.ValueMember = table.Columns("UserID").ToString
        cboUsers.DisplayMember = table.Columns("User").ToString

        cboUsers.DataSource = New BindingSource(table, Nothing)

Can you see anything wrong?

Your submission gave me back the user ID, I'm looking to get back the username associated with that user ID

So that it would say "Thanks John" instead of "Thanks J101"

Its ok I solved it, I had to change the combobox selectedvalue to the "user" field in another part of my code, as it was currently the userID field!


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.