asp.net - Posting data to a SQL Table via vb.net Form with an onClick Submit button -


i'm new vb.net , i'm working on project in visual studio 2015. in 1 of application's tab i'm trying insert new records sql table via form post, once click button nothing happens , no new records added. current code below, great! thanks:

contact.aspx

<%@ page title="contact" language="vb" masterpagefile="~/site.master" autoeventwireup="true" codefile="contact.aspx.vb" inherits="contact" %> <asp:content runat="server" id="bodycontent" contentplaceholderid="maincontent"> <head> <meta charset="utf-8"> </head> <body> <br /> <p style="font-size: 15px;">fill out form below , click submit once completed:</p> <form id="submitdata" method="post"> <fieldset>   <p><label for="term">term:</label>   <input type="text" name="term" required />*   </p>    <p><label for="genre">definition:</label>      <input type="text" name="definition" required />*   </p>    <p><label for="year">long description:</label>      <textarea rows="3" type="text" name="longdescription" required></textarea>*   </p>   <p><label for="title">category:</label>      <select name="category" style="width: 312px; height: 31px; font-family: arial, helvetica, sans-serif; font-size: 1.2em;">       <option selected="selected">       <option value="branding">branding</option>       <option value="business">business</option>       <option value="business management">business management</option>       <option value="crm">crm</option>       <option value="communications">communications</option>       <option value="dental health">dental health</option>       <option value="education">education</option>       <option value="general">general</option>       <option value="governmental">governmental</option>       <option value="it">it</option>       <option value="marketing">marketing</option>       <option value="nutrition">nutrition</option>       <option value="state laws">state laws</option>       <option value="other">other...</option>     </select>   </p>     <p><label for="title">date loaded:</label>      <input type="text" name="dateloaded" id="datepicker" required />*   </p>     <p><label for="title">provided (your name):</label>      <input type="text" name="providedby" required />*   </p>     <p><label for="title">department:</label>      <input type="text" name="department" required />*   </p>     <p><label for="title">internal expert or sme topic:</label>      <input type="text" name="sme" />   </p>    <p><asp:button id="buttonsubmit" runat="server" onclick="buttonsubmit_click" text="submit" /></p> </fieldset>   </form> <br /> <p>* please allow between 24 48 hours have term added dictionary.</p> <br /> <a style="font-size: 16px; font: bold; background-color: black; color:white; text-decoration:none; padding:5px;" href="default.aspx">back</a> </body> </asp:content> 

contact.aspx.vb

partial class contact  inherits page  protected sub buttonsubmit_click(sender object, e eventargs)     dim sqlconnection1 new data.sqlclient.sqlconnection("connectionstring here")      dim cmd new data.sqlclient.sqlcommand     cmd.commandtype = system.data.commandtype.text     cmd.commandtext = "insert table_terms (term, definition, longdescription, category, dateloaded, providedby, department, sme) values (term, definition, longdescription, category, dateloaded, providedby, department, sme)"     cmd.connection = sqlconnection1      sqlconnection1.open()     cmd.executenonquery()     sqlconnection1.close()  end sub  end class 

any hint great. lot!

m.c.

your command text jacked up. strings need quoted, instance. try running statement in ssms. if doesn't work there it's not going work .net.

also, you're doing security issue. use stored procedures , pass values parameters. building statement execute in .net lead both worse performance , injection vulnerability.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -