vb.net 2010 - How to insert ALL items in combobox to mysql one column? -


all items on combobox should go database. should appear when after form1 load. code in inserting not working. hope me

private sub form1_load(byval sender system.object, byval e system.eventargs) handles mybase.load     dim 1 string      conn.open()     query = "select * dbgradeslip.student"     cmd = new mysqlcommand(query, conn)     dr = cmd.executereader     while dr.read         dim fn = dr.getstring("firstname") + ", "         dim mn = dr.getstring("middlename") + " "         dim ln = dr.getstring("lastname")         1 = ln.substring(0, 1)         2 = combobox6.items.add(fn + mn + one)     end while       = 0 combobox6.items.count         query = "insert student (fullname) values ('" & combobox6.items.tostring & "')"         cmd = new mysqlcommand(query, conn)         da.selectcommand = cmd     next     conn.close()  end sub 

you should call executenonquery on mysqlcommand execute query.

query = "insert student (fullname) values (@fullname)" cmd = new mysqlcommand(query, conn)     cmd.parameters.addwithvalue("@fullname", "") = 0 combobox6.items.count     cmd.parameters["@fullname"].value = combobox6.items(i).tostring()     cmd.executenonquery() next 

other should use parameterized query instead of (wrong) string concatenation. parameterized query avoid sql injections , parsing problem strings contains quotes. finally, access individual item in items collection need use indexer.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -