hi my name is mina i made that code for the web form when i check on the check box if i have a error on the main form it doent add the data on the persondata tabe on the other hand the code addes true or fulse in the other table whats is wrong with that code
<pre><%@ Page Language="C#" AutoEventWireup="true" Debug="true" Trace="false" CodeBehind="WebForm2.aspx.cs" Inherits="Learn_Asp.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="StyleSheet1.css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server" EnableViewState="False" ViewStateMode="Disabled"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" EnableViewState="False" ViewStateMode="Disabled"></asp:TextBox>
</td>
<td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" EnableViewState="False" ViewStateMode="Disabled"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label6" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox4" runat="server" EnableViewState="False" ViewStateMode="Disabled"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label7" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox5" runat="server" EnableViewState="False" ViewStateMode="Disabled"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label8" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td><asp:Label ID="Label9" runat="server" Text="Label"></asp:Label></td>
<td><asp:TextBox ID="TextBox7" runat="server" EnableViewState="False" ViewStateMode="Disabled"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" EnableViewState="False" ViewStateMode="Disabled" />
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" EnableViewState="False" ViewStateMode="Disabled" />
</td>
</tr>
</table>
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
that is the asp code
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
namespace Learn_Asp
{
public partial class WebForm2 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("data Source=localhost; Initial Catalog =personal; Integrated Security = true");
protected void Page_Init(object sender,EventArgs e)
{
TextBox1.AutoCompleteType = AutoCompleteType.FirstName;
TextBox2.AutoCompleteType = AutoCompleteType.LastName;
TextBox3.AutoCompleteType = AutoCompleteType.HomePhone;
TextBox4.AutoCompleteType = AutoCompleteType.FirstName;
TextBox5.AutoCompleteType = AutoCompleteType.Email;
TextBox6.TextMode = TextBoxMode.Password;
TextBox7.TextMode = TextBoxMode.Password;
Label1.Text = "First Name";
Label2.Text = "Last Name";
Label3.Text = "Phone";
Label5.Text = "newsletter Subscription";
Label6.Text = "User Name";
Label7.Text = "Email";
Label8.Text = "Password";
Label9.Text = "Confirm Password";
Button1.Text = "Submit";
Button2.Text = "Reset";
CheckBox1.Checked = false;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("InsertTable", con);
int added = 0;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@personFname", TextBox1.Text);
cmd.Parameters.AddWithValue("@personLname", TextBox2.Text);
cmd.Parameters.AddWithValue("@personPhone", Convert.ToDecimal(TextBox3.Text));
cmd.Parameters.AddWithValue("@username", TextBox4.Text);
cmd.Parameters.AddWithValue("@email", TextBox5.Text);
cmd.Parameters.AddWithValue("@password", TextBox6.Text);
cmd.Parameters.AddWithValue("@ConfirmPassword", TextBox7.Text);
try
{
con.Open();
added = cmd.ExecuteNonQuery();
if (added > 0 || added < 0)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
Label4.Text = "";
}
Label4.Text = added.ToString() + "record Inserted";
}
catch(Exception err)
{
Label4.Text = "cant insert the record because " + err.Message ;
}
finally
{
con.Close();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
Label4.Text = "";
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
SqlCommand connection = new SqlCommand("checking", con);
connection.CommandType = CommandType.StoredProcedure;
connection.Parameters.AddWithValue("@Subsecribe", Convert.ToInt16(CheckBox1.Checked));
if (IsPostBack)
{
try
{
con.Open();
connection.ExecuteNonQuery();
}
catch (Exception err)
{
Label4.Text = "cant insert the record because " + err.Message;
}
finally
{
con.Close();
}
}
else
{
con.Close();
Label4.Text = "Connction Closed";
}
}
}
}
USE [Personal]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[personData](
[personID] [int] IDENTITY(1,1) NOT NULL,
[personFname] [varchar](1000) NOT NULL,
[personLname] [varchar](1000) NOT NULL,
[personPhone] [bigint] NOT NULL,
[username] [varchar](100) NOT NULL,
[email] [varchar](500) NOT NULL,
[pasword] [varchar](15) NOT NULL,
[ConfirmPassword] [varchar](15) NOT NULL,
PRIMARY KEY CLUSTERED
(
[personID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UQ_email] UNIQUE NONCLUSTERED
(
[email] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UQ_PhoneNumber] UNIQUE NONCLUSTERED
(
[personPhone] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UQ_username] UNIQUE NONCLUSTERED
(
[username] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
USE [Personal]
GO
/****** Object: Table [dbo].[NewsLetter] Script Date: 8/7/2019 8:18:46 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[NewsLetter](
[NewsId] [int] IDENTITY(1,1) NOT NULL,
[Subsecribe] [bit] NOT NULL,
[personID] [int] NULL,
PRIMARY KEY CLUSTERED
(
[NewsId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[NewsLetter] WITH CHECK ADD CONSTRAINT [FK_PersonID] FOREIGN KEY([personID])
REFERENCES [dbo].[personData] ([personID])
GO
ALTER TABLE [dbo].[NewsLetter] CHECK CONSTRAINT [FK_PersonID]
GO
USE [Personal]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[checking]
(
@Subsecribe bit
)
as
begin
begin transaction;
insert into NewsLetter(Subsecribe)values(@Subsecribe);
commit transaction;
end;
USE [Personal]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[InsertTable]
(
@personFname varchar(1000),
@personLname varchar(1000),
@personPhone bigint,
@username varchar(100),
@email varchar(500),
@password varchar(15),
@ConfirmPassword varchar(15)
)
as
BEGIN
BEGIN TRANSACTION;
insert into personData(personFname,personLname,personPhone,username,email,pasword,ConfirmPassword)
values(@personFname,@personLname,@personPhone,@username,@email,@password,@ConfirmPassword);
COMMIT TRANSACTION;
END;
that is the c3 code
w
What I have tried:
i tried to make one to one relatioship in the data base but it doent work