title: Inserting Data from Asp.net Webpage into local SQL express database
body: <p>very new to coding, i'm basically trying to create a asp website that will display data in a grid, which i got working fine ( simple enough ) however i want to be able to add it</p>
  
  <p>i've got a default.aspx where my data is presented and an Add.aspx which is my insert page.</p>
  
  <p>i've got 4 text boxes which i use to type data into and on push of a button it will insert the data into the sql express db i have running,</p>
  
  <p>im running , 1 DB with 1 table, so you can understand how simple my little project is.</p>
  
  <p>i ran debugs and i got no issues:</p>
  
  <p>code for default.aspx
  <i>  </p>
  
  <pre><code>&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;strong style="border-style: ridge"&gt;:: Server List Details Page ::&lt;/strong&gt;
  &lt;p&gt;&lt;/p&gt;
  
  
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
      &lt;/div&gt;
  
              &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
          DataSourceID="SqlDataSource1" AllowSorting="True"&gt;
                  &lt;Columns&gt;
                      &lt;asp:BoundField DataField="ServerName" HeaderText="ServerName" 
                          SortExpression="ServerName" /&gt;
                      &lt;asp:BoundField DataField="IPAddress" HeaderText="IPAddress" 
                          SortExpression="IPAddress" /&gt;
                      &lt;asp:BoundField DataField="Description" HeaderText="Description" 
                          SortExpression="Description" /&gt;
                      &lt;asp:BoundField DataField="Location" HeaderText="Location" 
                          SortExpression="Location" /&gt;
                  &lt;/Columns&gt;
              &lt;/asp:GridView&gt;
              &lt;asp:Button ID="Add" runat="server" Text="Add Device" OnClick="Add_click" OnClientClick="window.open('add.aspx', 'add');"/&gt;
  
      &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
          ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;" 
  
          SelectCommand="SELECT [ServerName], [IPAddress], [Description], [Location] FROM [Table1]"&gt;
      &lt;/asp:SqlDataSource&gt;
      &lt;/form&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p></i></p>
  
  <p>code for ADD.aspx
  <i></p>
  
  <pre><code>    &lt;title&gt;&lt;/title&gt;
      &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;strong&gt;:: Add Device Details ::
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;/strong&gt;
  
      Server Name:
      &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;br /&gt;
      IP Address:&amp;nbsp;&amp;nbsp;&amp;nbsp; 
      &lt;asp:TextBox ID="TextBox2" runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;br /&gt;
      Description:&amp;nbsp;&amp;nbsp;&amp;nbsp;
      &lt;asp:TextBox ID="TextBox3" runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;br /&gt;
      Location:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
      &lt;asp:TextBox ID="TextBox4" runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      &lt;asp:Button ID="Generate_Data" runat="server" Text="Generate Data" 
          onclick="Generate_Data_Click" PostBackUrl="~/Default.aspx" /&gt;
      &lt;/form&gt;
  
  
  
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p></i></p>
  
  <p>Code for Button to submit information:
  <i></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Data.SqlClient;
  
  
  namespace Table_to_DB
  {
      public partial class WebForm2 : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
  
          }
  
          protected void Generate_Data_Click(object sender, EventArgs e)
          {
              SqlConnection cn = new SqlConnection("Data Source= 172.17.10.89; initial catalog=database1");
  
              SqlCommand cmd = new SqlCommand("INSERT INTO database1 (" + " servername, ipaddress, description, Location " + ") VALUES (" + " @TextBox1.text, @TextBox2.text, @TextBox3.text, @TextBox4.text" + ")", cn);
  
              cn.Open();
              cmd.ExecuteNonQuery();
              cn.Close();
  
          }
      }
  }
  </code></pre>
  
  <p></i></p>
  
  <p>The problem im having is that when i input my data and submit it, nothing errors and no data ends up in the table.</p>
  
  <p>please help, most of this code i got off the net and im still learning.</p>