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:
selectedindexgets index of selected item.selecteditemgets object that's selected.selectedtextgets text that's selected.selectedvaluegets 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
Post a Comment