gpt4 book ai didi

c# - .NET中的注册页面错误

转载 作者:行者123 更新时间:2023-12-03 08:57:35 24 4
gpt4 key购买 nike

我是.NET和C# Realm 的新手。
我正在为我正在工作的网站创建注册页面。
注册到我正在创建的网站时,我一直收到错误消息。输入我的详细信息时,它不会将我注册到数据库。
我在数据库中创建了一个表(我创建了connectionString),但我无法注册-我收到一个异常消息,提示“错误,请尝试重新注册”(就像我所做的那样)。
有人知道我在做什么错吗?谢谢!

这是我的代码和图像:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

public partial class Registration : System.Web.UI.Page

{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegisConnectionString"].ConnectionString);
con.Open();
string cmdStr = "Select count(*) from Table where Username='" + TextBox1Username.Text + "'";
SqlCommand userExist = new SqlCommand(cmdStr, con);
// int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
con.Close();
/* if (temp == 1)
{
Response.Write("username already exists");
} */
}
}


protected void TextBox2_TextChanged(object sender, EventArgs e)
{

}


protected void Submit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegisConnectionString"].ConnectionStr ing);
con.Open();
string insCmd = "Insert into Table (Username, Password, EmailAddress,Fullname, City) values (@Username, @Password, @EmailAddress, @Fullname, @City)";
SqlCommand insertUser = new SqlCommand(insCmd, con);
insertUser.Parameters.AddWithValue("@Username", TextBox1Username.Text);
insertUser.Parameters.AddWithValue("@Password", TextBox2Password.Text);
insertUser.Parameters.AddWithValue("@EmailAddress", TextBox4Email.Text);
insertUser.Parameters.AddWithValue("@Password", TextBox2Password.Text);
insertUser.Parameters.AddWithValue("@City", TextBox6City.Text);

try
{
insertUser.ExecuteNonQuery();
con.Close();
Response.Redirect("Login.aspx");
}
catch (Exception er)
{
Response.Write("error,please try registering again");
}

}

}

图片:

[URL = http://imageshack.us/photo/my-images/4/os6b.jpg/] [IMG = http://img4.imageshack.us/img4/2526/os6b.jpg] [/IMG] [/URL]

通过[URL = http://imageshack.us] ImageShack.us [/URL]上传

最佳答案

您的参数中缺少全名,并且两次输入密码,请修复该密码并再次运行。

另外,在catch块中。您应该使用异常消息来调试或记录在可以清楚看到错误的位置。您现在拥有的方式会给出您输入的错误。不是实际的消息。

这是他们正在讨论有关sqlexception的链接。捕获这一点可能是个好主意。

SqlException catch and handling

关于c# - .NET中的注册页面错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19306813/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com