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
Post a Comment