no errors but data is not updated

chi2king

Member
Joined
Sep 28, 2006
Messages
20
Programming Experience
Beginner
Why is it that when i run this codes i get no errors (Label states that account is updated) BUT in reality at the database side no changes occurs at the data. ID is displayed in a label everytime the page loads. Thanks in advance.


VB.NET:
Dim DBConn As New Data.SqlClient.SqlConnection("DATA SOURCE = xxx; INITIAL CATALOG = xxx;Integrated Security=True")
        Dim DBCmd As New Data.SqlClient.SqlCommand
        Dim DBAdap As New Data.SqlClient.SqlDataAdapter
        Dim DS As New Data.DataSet
        DBConn.Open()
        Try
            DBCmd = New Data.SqlClient.SqlCommand("UPDATE LOG_IN SET EMAIL = @EMAIL, PASSWORD = @PASSWORD, FIRSTNAME = @FIRSTNAME, LASTNAME = @LASTNAME, GENDER = @GENDER, BIRTHDATE = @BIRTHDATE, BIRTHPLACE = @BIRTHPLACE WHERE ID = @ID", DBConn)
            
            DBCmd.Parameters.Add("@ID", Data.SqlDbType.Int).Value = Label1.Text
            DBCmd.Parameters.Add("@EMAIL", Data.SqlDbType.VarChar).Value = TextBox1.Text
            DBCmd.Parameters.Add("@PASSWORD", Data.SqlDbType.VarChar).Value = TextBox2.Text
            DBCmd.Parameters.Add("@LASTNAME", Data.SqlDbType.VarChar).Value = TextBox3.Text
            DBCmd.Parameters.Add("@FIRSTNAME", Data.SqlDbType.VarChar).Value = TextBox4.Text
            DBCmd.Parameters.Add("@GENDER", Data.SqlDbType.VarChar).Value = TextBox7.Text
            DBCmd.Parameters.Add("@BIRTHDATE", Data.SqlDbType.VarChar).Value = TextBox6.Text
            DBCmd.Parameters.Add("@BIRTHPLACE", Data.SqlDbType.VarChar).Value = TextBox5.Text
 
            DBCmd.ExecuteNonQuery()
            Label7.Text = ("Your account is updated.")
            DBAdap = New Data.SqlClient.SqlDataAdapter("SELECT * FROM LOG_IN", DBConn)
            DBAdap.Fill(DS)
            DataBind()
        Catch ex As Exception
            Label7.Text = ("Your account was not updated.")
        End Try
        DBCmd.Dispose()
        DBAdap.Dispose()
        DBConn.Close()
        DBConn = Nothing
 
Hi,

I am not very sure also but try this:

VB.NET:
Try
        Dim DBConn As New Data.SqlClient.SqlConnection("DATA SOURCE = xxx; INITIAL CATALOG = xxx;Integrated Security=True")
        Dim DBCmd As Data.SqlClient.SqlCommand
        Dim DBAdap As Data.SqlClient.SqlDataAdapter
        Dim DS As New Data.DataSet
        DBConn.Open()
        .... .... ....
Catch ex as exception
        .....  .......
End Try

I put the declarations inside the try and remove "NEW" from the declarations of DBCmd and DBAdap. Since inside your coding, you will be calling New SqlCommand and New SqlDataAdapter, there shouldn't be New in your declaration.
 
thanks for answering. I still have the same problem (data is not updated eventhough there are no errors in running the code)
 
I solved this problem by trial and error(since im still new to asp.net).


I just enclosed all my codes in the Page_Loads into a :

If Not Page.IsPostBack Then
........my codes on page load..........
End If


Thanks.
 
Back
Top