【发布时间】:2017-12-01 20:28:36
【问题描述】:
我无法将用户输入的数据从 .cs 导入表格。我有 2 个表,其中一个包含所有用户详细信息,而另一个则包含用户名(名字)和密码。除了密码和用户名,数据进入详细信息表。 这是来自.cs的代码
公共部分类注册:System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
}
protected void btnReg_Click(object sender, EventArgs e)
{
string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
//string encryption = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "SHA1");
SqlCommand cmd2 = new SqlCommand("sp_PasswordStorage", con);
SqlCommand cmd = new SqlCommand("sp_procedure", con);
cmd2.CommandType = CommandType.StoredProcedure;
cmd.CommandType = CommandType.StoredProcedure;
if (Page.IsValid)
{
cmd.Parameters.AddWithValue("@Fname", txtFname.Text);
cmd2.Parameters.AddWithValue("@uname", txtFname.Text);
cmd2.Parameters.AddWithValue("@pswd", Encryption(txtPassword.Text));
cmd.Parameters.AddWithValue("@Lname", txtLname.Text);
cmd.Parameters.AddWithValue("@Age", txtAge.Text);
cmd.Parameters.AddWithValue("@eid", txtEmail.Text);
cmd.Parameters.AddWithValue("@pno", txtPhone.Text);
cmd.Parameters.AddWithValue("@city", txtCity.Text);
cmd.Parameters.AddWithValue("@country", txtCountry.Text);
cmd.Parameters.AddWithValue("@gender", dropGender.SelectedItem.Value);
cmd.Parameters.AddWithValue("@role", dropRole.SelectedItem.Value);
con.Open();
cmd.ExecuteNonQuery();
//MessageBox.Show("Registration successfully");
Server.Transfer("MainPage.aspx", true);
}
else
{
MessageBox.Show("Registration Failed");
MessageBox.Show("Please Try Again Later");
Server.Transfer("MainPage.aspx", true);
}
}
}
public string Encryption(string value)
{
SHA1 algorithm = SHA1.Create();
byte[] data = algorithm.ComputeHash(Encoding.UTF8.GetBytes(value));
string sh1 = "";
for (int i = 0; i < data.Length; i++)
{
sh1 += data[i].ToString("x2").ToUpperInvariant();
}
return sh1;
}
}
}
任何帮助将不胜感激,谢谢:)
【问题讨论】:
-
您预计会发生什么?实际发生了什么?运行时是否发生异常? (如果是,它们是什么)?
-
可能值得将代码包装在
catch中? -
当前代码有什么问题?你有什么错误吗?您是否调试并检查代码中发生了什么?您是否检查了数据库是否插入了数据?您只执行
cmd而不是cmd2。你注意到了吗? -
不,没有错误,它只是正常运行。并且在数据库中,1 个表获取记录,而另一个则没有。我不知道 Wrapconcept 会调查那个。