Note that there are some explanatory texts on larger screens.

plurals
  1. POhtml forms with c# code
    primarykey
    data
    text
    <p>So I am trying to have a button when clicked it sends data to an sql server. I thought i could just create a form that would only have a submit button and I would handle that submit button in my home controller.</p> <p>My html is as such:</p> <pre><code>&lt;body&gt; &lt;div style="border: solid; max-width: 300px; margin-left: auto; margin-right: auto"&gt; @using(Html.BeginForm()) { &lt;input type="submit" value="Vote"/&gt; } &lt;/div&gt; &lt;/body&gt; </code></pre> <p>in my home controller i thought it was supposed to handle the form such as:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Data.SqlClient; namespace WAgermanClub.Controllers { public class HomeController : Controller { [HttpPost] public ActionResult add(string vote1) { SqlConnection vote1connection = new SqlConnection("user id=userid;" + "password=validpassword;server=o5z5dpwpzi.database.windows.net;" + "Trusted_Connection=yes;" + "database=wagermanclub_votes; " + "connection timeout=30"); try { vote1connection.Open(); } catch (Exception g) { Console.WriteLine(g.ToString()); } try { SqlDataReader myReader = null; SqlCommand myCommand = new SqlCommand("select * from table", vote1connection); myReader = myCommand.ExecuteReader(); while (myReader.Read()) { Console.WriteLine(myReader["Vote1"].ToString()); } } catch (Exception i) { Console.WriteLine(i.ToString()); } SqlCommand vote1command = new SqlCommand("INSERT INTO table (Column1, Vote1) " + "Values (1, 'Vote1' + 1)", vote1connection); vote1command.ExecuteNonQuery(); try { vote1connection.Close(); } catch (Exception h) { Console.WriteLine(h.ToString()); } } } } </code></pre> <p>It all looks fine except for I get an error saying that in the add(string vote1) not all code paths return a value. What am I doing wrong? I do not have that great of a grip on html forms but I feel that once I get this it will lead to a better understanding. </p> <p>All help appreciated! Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload