2016-06-08 70 views
0

所以我一直堅持這個很長一段時間,無法確定它爲什麼不工作。這是一個註冊頁面,在提交信息後,應該將數據(我選擇的那個,不是所有註冊選項輸入數據庫)上載到數據庫內的一個表(稱爲tbl)(稱爲Database2.mdf)。這是通過Visual Studio 2010.還有一個Java階段檢查信息,但我不認爲這是導致問題的原因,所以我只需發佈SQL代碼和HTML代碼以及表格線。有人能告訴我爲什麼這段代碼不工作嗎?

的SQL位:

<%@ Page Language="C#" %> 
<%@ Import Namespace="System.Data.SqlClient" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<script runat="server"> 

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (Request.Form["sub"] != null) 
    { 
     string fName = Request.Form["FName"]; 
     string lName = Request.Form["LName"]; 
     string uName = Request.Form["UName"]; 
     string Street = Request.Form["Street"]; 
     string City = Request.Form["City"]; 
     string Pass = Request.Form["Password"]; 
     string PassCon = Request.Form["PasswordConf"]; 
     string Email = Request.Form["Email"]; 
     string Comments = Request.Form["Comment"]; 
     int ID = int.Parse(Request.Form["ID"]); 
     string conStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database2.mdf;Integrated Security=True;User Instance=True"; 
     string cmdStr = string.Format("INSERT INTO tbl (FirstName, LastName, UserName, Street, City, Password, PasswordConfirm, Email, Comments, IdentificationNumber) VALUES (N'{0}', N'{1}', N'{2}', N'{3}', N'{4}', N'{5}', N'{6}', N'{7}', N'{8}', {9})", fName, lName, uName, Street, City, Pass, PassCon, Email, Comments, ID); 
     SqlConnection conObj = new SqlConnection(conStr); 
     SqlCommand cmdObj = new SqlCommand(cmdStr, conObj); 
     conObj.Open(); 
     cmdObj.ExecuteNonQuery(); 
     conObj.Close(); 
    } 

} 
</script> 

的HTML位:(CheckForm是Javassript行動,檢查是否符合形式要求的名稱,也Registration.aspx是註冊頁面顯然,這是未鏈接到主頁)

<form action="Registration.aspx" method="post" name="ContactForm" 
onsubmit="return CheckForm()"> 
    First Name: 
    <input type="text" size="65" name="FName" /> 
    <br /> 
    Last Name: 
    <input type="text" size="65" name="LName" /> 
    <br /> 
    Username: 
    <input type="text" size="65" name="UName" /> 
    <br /> 
    Street: 
    <input type="text" size="65" name="Street" /> 
    <br /> 
    City: 
    <input type="text" size="65" name="City" /> 
    <br /> 
    Password: 
    <input type="password" size="65" name="Password" /> 
    <br /> 
    Password Confimration: 
    <input type="password" size="65" name="PasswordConf" /> 
    <br /> 
    E-mail Address: 
    <input type="text" size="65" name="Email" /> 
    <br /> 
    Comments: 
    <input type="text" size="100" name="Comment" /> 
    <br /> 
    Identification Number: 
    <input type="password" size="65" name="ID" /> 
    <br /> 
    Mobile : 
    <input type="text" id="mobile" name="mobile" style="width: 40px;" maxlength="3" /> 
    - 
    <input type="text" name="mobile1" maxlength="7" /> 
    <br /> 
    Gender: Male<input type="radio" name="gender" id="gender_Male" value="Male" checked /> 
    Female<input type="radio" name="gender" id="gender_Female" value="Female" /> 
    <br /> 
    Which countries would you like to recieve political news for?: 
    <br /> 
    <input type='checkbox' name='files[]' id='1' value='1' /> 
    Israel 
    <input type='checkbox' name='files[]' id='2' value='2' /> 
    Russia 
    <input type='checkbox' name='files[]' id='3' value='3' /> 
    Canada 
    <br /> 
    How often do you read the newspaper? 
    <br /> 
    <select id="cardtype" name="sel"> 
     <option value=""></option> 
     <option value="1">Never</option> 
     <option value="2">Everyday</option> 
     <option value="3">Once a week</option> 
     <option value="4">Once a year</option> 
    </select> 
    <br /> 
    What can we help you with? 
    <select type="text" value="" name="Subject"> 
     <option></option> 
     <option>Customer Service</option> 
     <option>Question</option> 
     <option>Comment</option> 
     <option>Consultation</option> 
     <option>Other</option> 
    </select> 
    <br /> 
    <input type="submit" value="Send" name="submit" /> 
    <input type="reset" value="Reset" name="reset" /> 
    </form> 

表線如下:

  • FirstN AME - 爲nvarchar(50)
  • 名字 - 爲nvarchar(50)
  • 用戶名 - 爲nvarchar(50)
  • 街 - 爲nvarchar(50)
  • 市 - 爲nvarchar(50)
  • 密碼 - 爲nvarchar(50 )
  • PasswordConfirm - 爲nvarchar(50)
  • 電子郵件 - 爲nvarchar(50)
  • 評論 - 爲nvarchar(50) - 只有一個允許空值
  • Identi ficationNumber - int

我知道這是一個很好的篩選,但我一直堅持它很長一段時間,我必須得到它很快修復,我非常感謝任何幫助提供!提前致謝!

+0

您是否嘗試過使用瀏覽器調試器來查看是否有任何錯誤? – Lexi

回答

0

你說的必須完成的篩選量是正確的。

我會做的第一件事是運行瀏覽器調試器,看看彈出的錯誤。然後,將這些錯誤添加到此問題。

隨着這些信息,你有什麼嘗試?你還沒有嘗試過什麼?

從我在這個論壇和其他論壇上看到的是,當你問一個問題時,你對自己有什麼沒有嘗試過的程度越詳細,以及程序應該做什麼,你會得到更詳細的和更快速的幫助答案。

p.s.人們不想浪費時間回答措詞不清或模糊的問題。所以,描述性確實有幫助。

相關問題