函数被调用两次

时间:2012-06-20 10:11:29

标签: sql-server-2008 vb.net-2010

我可以知道为什么AddAccount在我的CreateUser只被触发一次时被解雇了两次?我只需要激活一次AddAccount。

Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
    Dim Account As New Account
    Dim User As New User
    Dim DateCreated As String = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")
    Dim UserID As Integer
    UserID = User.CreateUser(lblName.Text, lblGender.Text, lblDOB.Text, lblContact.Text, lblAddress.Text)
    Account.AddAccount(lblEmail.Text, lblPassword.Text, lblSecurityCode.Text, DateCreated, UserID)
    Response.Redirect("~/ThankYou.aspx")
End Sub

AddAccount类中的代码

 Public Sub AddAccount(ByVal EmailVal As String, ByVal PassVal As String, ByVal SecurityCodeVal As String,
                          DateCreatedVal As String, ByVal UserIDVal As Integer)
        Dim strConn As String
        strConn = ConfigurationManager.ConnectionStrings("HomeFurnitureConnectionString").ToString
        Dim conn As New SqlConnection(strConn)
        Dim strSql As String
        strSql = "INSERT INTO Account(Email,Password,SecurityCode,DateCreated,Userid) " & _
                 "VALUES(@Email,@Password,@SecurityCode,@DateCreated,@Userid)"
        Dim cmd As New SqlCommand(strSql, conn)
        cmd.Parameters.AddWithValue("@Email", EmailVal)
        cmd.Parameters.AddWithValue("@Password", PassVal)
        cmd.Parameters.AddWithValue("@SecurityCode", SecurityCodeVal)
        cmd.Parameters.AddWithValue("@DateCreated", DateCreatedVal)
        cmd.Parameters.AddWithValue("@Userid", UserIDVal)
        Dim da As New SqlDataAdapter(cmd)
        Dim ds As New DataSet
        da.Fill(ds)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
    End Sub

由于

0 个答案:

没有答案