none
Cannot add data to MySQL Database from website form. RRS feed

  • Question

  • Is there a valid reason as to why I can't add data to my SQL Database from my web application despite doing everything correctly? I'm currently training in MySQL & C# & have been using the following training video:

    https://www.youtube.com/watch?v=POWm4EfU9bA

    I'm using MS Visual Studio and MS SQL Server Management Studio, I'm also using Azure Web + SQL service and I have opened up the firewall allowing my client IP address through. 

    Here is my coding which "apparently" adds data to my SQL database from the form located in my front end web application:

    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 xxxxxx
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
           
    
            protected void Page_Load(object sender, EventArgs e)
            {
                if (Page.IsPostBack == true)
                {
                    Label1.Text = ("Great job!");
                    
                }
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                SqlConnection stormconn = new SqlConnection("Server=tcp:xxxx.database.windows.net,1433;Initial Catalog=xxxx;Persist Security Info=False;User ID=xxxxx;Password=xxxxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");
                {
                    SqlCommand insert = new SqlCommand("EXEC dbo.InsertFullname @Fullname", stormconn);
                    insert.Parameters.AddWithValue("@Fullname", TextBox1.Text);
                 
    
                    stormconn.Open();
                    insert.ExecuteNonQuery();
                    stormconn.Close();
    
                    if (IsPostBack)
                    {
                        TextBox1.Text = ("");
                    }
                }
            }
        }
    }


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="bluecitywebapplication.WebForm1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">   
            <asp:Label ID="Label1" runat="server" Text="Label">Type your full name here</asp:Label>
            <br />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <input type="submit" value="submit" />
        </form>    
    </body>
    </html>
    /****** Object:  StoredProcedure [dbo].[InsertFullname]    Script Date: 03/02/2019 09:20:02 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:      <Author, , Name>
    -- Create Date: <Create Date, , >
    -- Description: <Description, , >
    -- =============================================
    ALTER PROCEDURE [dbo].[InsertFullname]
    (
        -- Add the parameters for the stored procedure here
        @Fullname nchar(30)
    )
    AS
    BEGIN
        -- SET NOCOUNT ON added to prevent extra result sets from
        -- interfering with SELECT statements.
        SET NOCOUNT ON
    
        -- Insert statements for procedure here
        INSERT INTO dbo.tblFullname (Fullname) VALUES (@Fullname)
    	
    END

    This is also the last line of the diagnostics section:

    The program '[17620] iisexpress.exe' has exited with code -1 (0xffffffff)
    

    Is there any reason as to why my coding isn't doing what I'm programming it to do?
    Thanks

    Todd




    Sunday, February 3, 2019 8:43 AM

All replies

  • Hi friend,

    Thanks for posting here.

    This forum is about the MSBuild(Discuss the Microsoft build engine aka MSBuild. Topics including: usage of MSBuild, build customization, and MSBuild extensibility via tasks, loggers and hosting.). 

    As your issue is more related to Web Form(asp.net), I suggest that you could open an new thread on the stackoverflow with asp.net and web form tag. More community members on that forum may further look at your issue and provide more suggestions.

    If you have some MSBuild questions, please feel free to contact us. We will try our best to give you a solution.

    Thanks for your understanding and cooperation.

    Best Regards

    Lance


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 4, 2019 6:51 AM