数据未保存在sql server(asp.net)中

a1o7rhls  于 2021-08-09  发布在  Java
关注(0)|答案(0)|浏览(192)

数据没有保存在数据库里,我真的不知道为什么。
ID放置正确,按钮已打开 OnClick="Button1_Click" .
当我搬家的时候 Response.Write("<script>alert('Testing');</script>");try 阻止它没有出现在屏幕上,无论我把它放在 if() 或者之后。
这是我的aspx.cs:

public partial class usersignup : System.Web.UI.Page
{
    string strcon = ConfigurationManager.ConnectionStrings["con"].ConnectionString;

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    // sing up button is clicked (connecting with the DB
    protected void Button1_Click(object sender, EventArgs e)
    {
      //Response.Write("<script>alert('Testing');</script>");

        try
        {
            SqlConnection con = new SqlConnection(strcon);
            if (con.State == ConnectionState.Closed)
            {
                con.Open();                    
            }

            SqlCommand cmd = new SqlCommand("INSERT INTO member_master_tbl(first_name, birthday, last_name, email, country, city, gender, address, username, password) " +
                " values(@first_name, @birthday, @last_name, @email, @country, @city, @gender, @address, @username, @password)", con);

            cmd.Parameters.AddWithValue("@first_name", TextBox1.Text.Trim());
            cmd.Parameters.AddWithValue("@birthday", TextBox2.Text.Trim());
            cmd.Parameters.AddWithValue("@last_name", TextBox3.Text.Trim());
            cmd.Parameters.AddWithValue("@email", TextBox4.Text.Trim());
            cmd.Parameters.AddWithValue("@country", DropDownList1.SelectedItem.Value);
            cmd.Parameters.AddWithValue("@city", TextBox6.Text.Trim());
            cmd.Parameters.AddWithValue("@gender", DropDownList2.SelectedItem.Value);
            cmd.Parameters.AddWithValue("@address", TextBox5.Text.Trim());
            cmd.Parameters.AddWithValue("@username", TextBox7.Text.Trim());
            cmd.Parameters.AddWithValue("@password", TextBox8.Text.Trim());
            //cmd.Parameters.AddWithValue("@account_status", "pending");

            cmd.ExecuteNonQuery();
            con.Close();
            Response.Write("<script>alert('Sign Up Successful. Go to User Login to Login');</script>");
        } 
        catch(Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message + "');</script>");
        }
    }
}

下面是数据库的样子:

SELECT TOP (1000) [first_name]
      ,[birthday]
      ,[last_name]
      ,[email]
      ,[country]
      ,[city]
      ,[gender]
      ,[address]
      ,[username]
      ,[password]
  FROM [elibraryDB].[dbo].[member_master_tbl]

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题