Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are missing an 's' from the <code>ConnectionStrings</code> indexed property. Once you fix that error, however, you will also find you are missing more 's' from the <code>SqlCommand.Parameters</code> property.</p> <p>To reveal these issues, open Properties of your code-behind file, and choose Build Action of Compile. (Also, I can see from your image that it looks like your project is setup as a Web Site rather than a Web Application; if possible, look into converting this over to a Web Application, as it offers a number of benefits.)</p> <p>Once you get your syntax corrected, then you should change your code so that the update is invoked through the button click handler, rather than on page load.</p> <p>In your markup code in the aspx:</p> <pre><code>&lt;asp:Button runat="server" ID="btnSave" Text="Save" OnClick="btnSave_Click" /&gt; </code></pre> <p>In your code-behind:</p> <pre><code>protected void btnSave_Click(object sender, EventArgs e) { string conn = ConfigurationManager.ConnectionStrings["welcome"].ConnectionString; using (SqlConnection con = new SqlConnection(conn)) { SqlCommand cmd = new SqlCommand("Insert into abhishek(pr_name,Add,add2) values(@ah,@Ap,@qe)", con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@ah", TextBox1.Text.Trim()); cmd.Parameters.AddWithValue("@ap", TextBox2.Text.Trim()); cmd.Parameters.AddWithValue("@qe", TextBox3.Text.Trim()); con.Open(); cmd.ExecuteNonQuery(); } } </code></pre> <p>Note that I have moved the code into the button click event handler, and <em>out of</em> the Page_Load. The Load event handler should only be used for initialization items needed unconditionally on the execution path of the page (i.e., regardless of whatever button was clicked on the page), and should look something like the following:</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { // Code to run every time the page is created, both initially and on postback if (IsPostBack) { // Code to run every time the page is posted back (any submit event) } else { // Code to run on the initial creation of the page } } </code></pre>
    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