我正嘗試在Visual Basic 2012上使用C#創建一個註冊頁面。當我調試時出現0錯誤,但是當我嘗試註冊一個帳戶時,出現以下錯誤。爲什麼我在')'錯誤附近得到不正確的語法?
「附近有語法錯誤)'」
如果我嘗試用現有的用戶名創建一個帳戶,它說用戶名已經存在。所以我能夠連接到SQL服務器,但我不知道我錯了哪裏。
這個註冊頁面應該建立在我的數據庫DNMembership帳戶>表>帳戶
這裏是我的代碼我的工作。
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegDNMembershipConnectionString"].ConnectionString);
con.Open();
string insCmd = "Insert into Accounts (AccountName, Passphrase, EmailAddress, FullName, Country)";
SqlCommand insertUser = new SqlCommand(insCmd, con);
insertUser.Parameters.AddWithValue("@AccountName", TextBoxUN.Text);
insertUser.Parameters.AddWithValue("@Passphrase", TextBoxPass.Text);
insertUser.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
insertUser.Parameters.AddWithValue("@FullName", TextBoxFN.Text);
insertUser.Parameters.AddWithValue("@Country", DropDownListCountry.SelectedItem.ToString());
try
{
insertUser.ExecuteNonQuery();
con.Close();
Response.Redirect("Login.aspx");
}
catch(Exception er)
{
Response.Write("<b>Something Really Bad Happened... Please Try Again.< /br></b>");
Response.Write(er.Message);
}
我做錯了什麼?
你需要掌握SQL上市的回答。它只在運行時執行。對於字符串中的SQL語法,您不會得到任何編譯器錯誤。 – Francis