我遇到了这段代码的麻烦。在我的数据库中,我将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