sql - Why is Data Not Saved to the Database in my Guestbook Application? -
i creating application requires guestbook.. data database appears on website data enter website doesn't automatically put database.
here code have..
protected sub butsign_click(sender object, e eventargs) handles butsign.click dim strdsn string = "provider=microsoft.jet.oledb.4.0;" & " data source=c:\users\shauna watson\desktop\project copies\final\app_data\factory.mdf" dim strsql string = (((("insert guestbook " & "( name,address,email,comments)" & "values ('") + txtname.text.tostring() & " ',' ") + txtaddress.text.tostring() & " ', '") + txtemail.text.tostring() & " ',' ") + txtcomments.text.tostring() & " ')" ' set access connection , select strings ' create oledbdataadapter dim myconn new oledbconnection(strdsn) 'create ole db command , call executenonquery execute ' sql statement dim mycmd new oledbcommand(strsql, myconn) try myconn.open() mycmd.executenonquery() catch exp exception console.writeline("error: {0}", exp.message) end try myconn.close() ' open thans.aspx page after adding entries guest book response.redirect("guestbookthanks.aspx") end sub
i'm wondering if can spot may have missed!
you try changing code this:
myconn.open() dim mycmd new oledbcommand mycmd .connection = myconn .commandtype = commandtype.text .commandtext = "insert guestbook (name,address,email,comments) values (@name,@address,@email,@comments)" .parameters.add("@name", oledbtype.varchar).value = txtname.text .parameters.add("@address", oledbtype.varchar).value = txtaddress.text .parameters.add("@email", oledbtype.varchar).value = txtemail.text .parameters.add("@comments", oledbtype.varchar).value = txtcomments.text end mycmd.executenonquery() myconn.close()
don't put in try block. if error, post it, , we'll see error is.
Comments
Post a Comment