שלום אני מנסה לחבר את דף ההרשמה שהכנתי לאתר שלי למסד נתונים sql server.
אני רוצה שהתוכן שאנשים מקלידים בדף ההרשמה יעבור למסד הנתונים ישמר שם.

זה הקוד שהכנתי לדף ההרשמה:

  חיבור דף הרשמה (form) למסד נתונים (sql server) בvisual studio 2015 ספוילר:  
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="insertData.aspx.cs" Inherits="insertData" %>


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Registration Form</title>
<style>
body {
height: 100%;
width: 100%;
background-image: url("http://i.imgur.com/dhqsa.jpg");
background-repeat: no-repeat;
background-size: cover;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader (src='.image.jpg',sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoade r(src='image.jpg',sizingMethod='scale')";
}
</style>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-32702423-1', 'emath.co.il');
ga('send', 'pageview');

</script>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-32702423-1', 'emath.co.il');
ga('send', 'pageview');

</script>

</head>
<body>
<div id="fb-root"></div>
<div id="fb-root"></div>


<form id="myform" method="post" action="">


<fieldset>


<center>
<h1><u><b>Site Registration Form</b></u></h1>
</center>


<legend>Registration</legend>


<h2><b><u>ID</u>: <input type="text" id="idNum" name="idNum" required placeholder="Enter your ID"></b></h2>


<h2><b><u>First Name</u>: <input type="text" id="fName" name="fName" required placeholder="Enter your first name"></b></h2>


<h2><b><u>Last Name</u>: <input type="text" id="lName" name="lName" required placeholder="Enter your last name" /></b></h2>


<h2><b><u>Age</u>: <input type="number" id="age" name="age" min="1" max="120" required></b></h2>


<h2><b><u>E-mail</u>: <input type="email" id="emailAddress" name="emailAddress" required placeholder="Enter legal email address"></b></h2>


<h2><b><u>Street Name</u>: <input type="text" id="streetName" name="streetName" required placeholder="Enter your street name"></b></h2>


<h2><b><u>City</u>:</b></h2><select id="cityName">
<option id="Ness Ziona" value="Ness Ziona">Ness Ziona</option>
<option id="Rehovot" value="Rehovot">Rehovot</option>
<option id="Rishon Lezion" value="Rishon Lezion">Rishon Lezion</option>
<option id="Holon" value="Holon">Holon</option>
<option id="Ramat Gan" value="Ramat Gan">Ramat Gan</option>
<option id="Beer Yaakov" value="Beer Yaakov">Beer Yaakov</option>
<option id="Eilat" value="Eilat">Eilat</option>
<option id="Beer Sheva" value="Beer Sheva">Beer Sheva</option>
<option id="Haifa" value="Haifa">Haifa</option>
<option id="Jerusalem" value="Jerusalem">Jerusalem</option>
<option id="Other" value="Other">Other</option>
</select>


<h2><b><u>Gender</u>:</b></h2>
<input type="radio" id="male" name="gender" value="Male" required> Male
<input type="radio" id="female" name="gender" value="Female"> Female


<h2><b><u>Interests</u>:</b></h2>
<input type="checkbox" id="Sports" name="interests" value="Sports">Sports<br>
<input type="checkbox" id="Music" name="interests" value="Music">Music<br>
<input type="checkbox" id="Computers" name="interests" value="Computers">Computers<br>
<input type="checkbox" id="Books" name="interests" value="Books">Books<br>
<input type="checkbox" id="other" name="interests" value="Other">Other<br>


<h2><b><u>Special Requests</u>: </b></h2>
<textarea rows="3" cols="50" id="specialRequests" name="specialRequests"></textarea><br>
<br/>


<button type="submit">Submit</button><br>


<input type="reset" value="Reset">
<br />


<button onclick="window.location.href='HtmlPage.html'">Hom e Page</button>


</fieldset>
</form>
</body>
</html>





וזה הקוד שאמור לחבר למסד הנתונים (aspx.cs):

  חיבור דף הרשמה (form) למסד נתונים (sql server) בvisual studio 2015 ספוילר:  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class insertData : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["submit"] != null)
{
string idNum = Request.Form["idNum"];
string fName = Request.Form["fName"];
string lName = Request.Form["lName"];
string age = Request.Form["age"];
string emailAddress = Request.Form["emailAddress"];
string streetName = Request.Form["streetName"];
string cityName = Request.Form["cityName"];
string gender = Request.Form["gender"];
string interests = Request.Form["interests"];
string specialRequests = Request.Form["specialRequests"];


string RegStatus;
string fileName = "db.mdf";
string tableName = "personalData";
string selectQuery = "SELECT * FROM " + tableName;


selectQuery += "WHERE ";
selectQuery += "idNum = '" + Request.Form["idNum"] + "'";


if (MyAdoHelper.I***ist(fileName, selectQuery))
{
RegStatus = ("This ID number already exists");
}


else
{
string sql = "INSERT INTO personalData (idNum, fName, lName, age, emailAddress, streetName, cityName, gender, interests, specialRequests) VAULES ('";
sql += idNum + "','" + fName + "','" + lName + "','" + age + "','" + emailAddress + "','" + cityName + "','" + gender + "','" + interests + "','" + specialRequests + "')";
MyAdoHelper.DoQuery(fileName, sql);
RegStatus = ("Registration was successful");
}


Response.Write(RegStatus);
Response.End();
}


}
}


וזו הטבלה עצמה בsql:

  חיבור דף הרשמה (form) למסד נתונים (sql server) בvisual studio 2015 ספוילר:  
CREATE TABLE personalData
(
[idNum] INT NOT NULL PRIMARY KEY ,
[fName] NVARCHAR(10) NOT NULL ,
[lName] NVARCHAR(10) NOT NULL ,
[age] INT NOT NULL,
[emailAddress] NVARCHAR(20) NOT NULL ,
[streetName] NVARCHAR(10) NOT NULL ,
[cityName] NVARCHAR(10) NOT NULL ,
[gender] NVARCHAR(6) NOT NULL ,
[interests] TEXT NULL ,
[specialRequests] TEXT NULL
)



הקודים הבאים אמורים להציג את הנתונים שהוכנסו לטבלה:

  חיבור דף הרשמה (form) למסד נתונים (sql server) בvisual studio 2015 ספוילר:  
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="showAllWithAdoHelper.aspx.cs" Inherits="showAllWithAdoHelper" %>


<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-32702423-1', 'emath.co.il');
ga('send', 'pageview');

</script>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-32702423-1', 'emath.co.il');
ga('send', 'pageview');

</script>

</head>
<body >
<%=usersList %>
</body>
</html>


  חיבור דף הרשמה (form) למסד נתונים (sql server) בvisual studio 2015 ספוילר:  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class showAllWithAdoHelper : System.Web.UI.Page
{
public string usersList;
protected void Page_Load(object sender, EventArgs e)
{
string fileName = "db.mdf";
string tableName = "personalData";
string selectQuery = "SELECT * FROM " + tableName;
usersList = MyAdoHelper.printDataTable(fileName, selectQuery).ToString();
}
}




אני לא יודע למה הקוד לא עובד, אז אם מישהו יוכל לעזור לי אני אשמח תודה מראש.