vb.net - How to get selected data from combobox and upload it to mysql database? -


i want selected data combobox , upload mysql database, it's not working expected. here code:

        try         dim cmd2 new mysqlcommand         dim insertstatment string = "insert comment (name,comment,reason)            values (@name,@comment, @reason)"         cmd2 = new mysqlcommand(insertstatment, db_con)         cmd2.parameters.addwithvalue("@name", txtname.text)         cmd2.parameters.addwithvalue("@comment", richtxtcomment.text)         cmd2.parameters.addwithvalue("reason", combobox.selectedvalue)          cmd2.executenonquery()         messagebox.show("thank your comment")      catch ex exception         messagebox.show("bad")         db_con.close()         exit sub     end try 

depending on how items in combobox added, there different properties use:

  • selectedindex gets index of selected item.
  • selecteditem gets object that's selected.
  • selectedtext gets text that's selected.
  • selectedvalue gets valuemember property of selected item.

so if didn't set valuemember property, it's going null. if want store what's displayed in combo box, use selectedtext:

cmd2.parameters.addwithvalue("@reason", combobox.selectedtext) 

if want store property or result of method of object in combobox use selecteditem:

cmd2.parameters.addwithvalue("@reason", combobox.selecteditem.tostring()) 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -