Cannot add data to MySQL Database from website form

  • Thread starter Thread starter Todd Gilbey
  • Start date Start date
T

Todd Gilbey

Guest
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:


View: 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

Continue reading...
 
Back
Top