asp.net - Insert into Database using OleDbConnection -


i finished code never inserted data database before. far sql statement works fine final execution of code don't know how do.

the new record doesn't show in database think missing few lines @ end makes new record execute.

protected sub insert_click(sender object, e eventargs) handles insert.click      dim v_date = datetext.text     dim v_username = usertext.text     dim v_phone = phonetext.text     dim v_email = emailtext.text     dim v_category = categorylist.text     dim v_short = shorttext.text     dim v_long = longtext.value      dim conn oledbconnection = new oledbconnection("provider=""*********"";user id=" & struserid & ";data source=" & strdatabase & ";password=" & strpsswd)      dim classifiedstr oledbcommand = new oledbcommand("insert tablename (date, username, phonenbr, email, category, description, fulldescription) values('" & v_date & "',lower('" & v_username & "'),'" & v_phone & "','" & v_email & "','" & v_category & "','" & v_short & "','" & v_long & "'", conn)     'classifiedstr.commandtype = commandtype.storedprocedure     dim oracledataadapterads oledbdataadapter = new oledbdataadapter     oracledataadapterads.selectcommand = classifiedstr     dim dsads dataset = new dataset     dsads.clear()     'oracledataadapterads.fill(dsads, "tablename")     conn.open()     'classifiedstr.executenonquery()   end sub 

update

error enter image description here

    dim v_date = datetext.text     dim v_username = usertext.text     dim v_phone = phonetext.text     dim v_email = emailtext.text     dim v_category = categorylist.text     dim v_short = shorttext.text     dim v_long = longtext.value      dim conn oledbconnection = new oledbconnection("provider=""********"";user id=" & struserid & ";data source=" & strdatabase & ";password=" & strpsswd)     conn.open()      dim classifiedstr oledbcommand = new oledbcommand("insert tablename (date, username, phonenbr, email, category, description, fulldescription) values(@v_date, lower(@v_username), @v_phone, @v_email, @v_category, @v_short, @v_long)", conn)     classifiedstr.parameters.add("@v_date", oledbtype.date).value = v_date     classifiedstr.parameters.add("@v_username", oledbtype.varchar).value = v_username     classifiedstr.parameters.add("@v_phone", oledbtype.varchar).value = v_phone     classifiedstr.parameters.add("@v_email", oledbtype.varchar).value = v_email     classifiedstr.parameters.add("@v_category", oledbtype.varchar).value = v_category     classifiedstr.parameters.add("@v_short", oledbtype.varchar).value = v_short     classifiedstr.parameters.add("@v_long", oledbtype.varchar).value = v_long      classifiedstr.executenonquery()     conn.close() 

you don't need use data adaptor, you're not returning , data client, instead, use executenonquery(), (with added parametrisation):

protected sub insert_click(sender object, e eventargs) handles insert.click     using conn new oledbconnection("provider=""*********"";user id=" & struserid & ";data source=" & strdatabase & ";password=" & strpsswd)         conn.open()          using classifiedstr new oledbcommand("insert t_classifieds (""date"", username, phonenbr, email, category, description, fulldescription) values(@v_date, lower(@v_username), @v_phone, @v_email, @v_category, @v_short, @v_long)", conn)             classifiedstr.parameters.add("@v_date", oledbtype.date).value = datetext.text             classifiedstr.parameters.add("@v_username", oledbtype.varchar).value  = usertext.text             classifiedstr.parameters.add("@v_phone", oledbtype.varchar).value = phonetext.text             classifiedstr.parameters.add("@v_email", oledbtype.varchar).value = emailtext.text             classifiedstr.parameters.add("@v_category", oledbtype.varchar).value = categorylist.text             classifiedstr.parameters.add("@v_short", oledbtype.varchar).value = shorttext.text             classifiedstr.parameters.add("@v_long", oledbtype.varchar).value = longtext.value              classifiedstr.executenonquery()         end using     end using end sub 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -