我遇到了這段代碼的麻煩。在我的數據庫中,我將Passphase列設置爲二進制(20)。爲了得到下面列出的代碼,我正在學習一個教程,但我調整了一些以適應我的需求。我的問題是,我不知道如何將密碼存儲爲二進制,而不是nvarchar。不允許將數據類型nvarchar隱式轉換爲二進制。使用CONVERT函數來運行此查詢。
這是註冊頁面到SQL服務器,如果這有所作爲。
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegDNMembershipConnectionString"].ConnectionString);
con.Open();
string insCmd = "Insert into Accounts (AccountName, Passphrase, EmailAddress, FullName, Country) VALUES (@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());
我很高興加入'VALUES'部分現在':)'什麼是TextBoxPass.Text的'價值「究竟?看起來你的價值不適合你的列類型。 –
您正在嘗試將「varchar」值發送到「二進制」類型的列。在提交之前,您需要在'TextBoxPass.Text'中轉換數據。 –
感謝Evan的回覆,但是我知道那是需要做的。它在錯誤中表示它。不幸的是,我對這一切都很陌生,我不知道如何去做。 – user3219150