2 Replies - 892 Views - Last Post: 07 August 2015 - 05:17 AM Rate Topic: -----

#1 Munawar.cma   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 21-July 15

Why my databse is not updating ?

Posted 05 August 2015 - 04:57 AM

I am updating my database by updating command in vb.net but getting no results I mean its not updating please help over this. Is there anything wrong in my code. Advise ....
Function to Update is
Public Function UpdateSchool(ByVal procedurename As String) As Boolean
        Dim flag As Boolean = False
        Try
            Dim sqlcon As SqlConnection = objDAL.Connection
            Dim sqlcmd As New SqlCommand(procedurename, sqlcon)
            sqlcmd.CommandType = CommandType.Text
            sqlcmd.Parameters.AddWithValue("@SchoolID", SID)
            sqlcmd.Parameters.AddWithValue("@SchoolName", Me.Txt_Fname.Text)
            sqlcmd.Parameters.AddWithValue("@Address", Me.Txt_Add.Text)
            sqlcmd.Parameters.AddWithValue("@City", Me.txtCity.Text)
            sqlcmd.Parameters.AddWithValue("@State", Me.txtState.Text)
            sqlcmd.Parameters.AddWithValue("@Contact1", Me.Txt_Ph.Text)
            sqlcmd.Parameters.AddWithValue("@Contact2", Me.Txt_Ph.Text)
            sqlcmd.Parameters.AddWithValue("@EmailID", Me.Txt_Mail.Text)
            sqlcmd.Parameters.AddWithValue("@Website", Me.txtWebsite.Text)
            sqlcmd.Parameters.AddWithValue("@Remarks", Me.Txt_Vat.Text)
            sqlcon.Open()
            Dim rowaffected As Integer = sqlcmd.ExecuteNonQuery()
            sqlcmd.Dispose()
            sqlcon.Close()
            MsgBox("School Information is Updated Successfully", MsgBoxStyle.Information + MsgBoxStyle.Information)
            flag = True
            Return flag
        Catch ex As Exception
            MsgBox(ex.Message)
            'MsgBox("School Information is not Updated Successfully. Please Try Again", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
            Return flag
        End Try
    End Function

Command/Event to update is
Private Sub btnFinish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinish.Click
        Dim str As New StringBuilder
        str.Append(validated.Validate(Txt_Fname, True, validated.StringAll, "SchoolName"))
        If str.Length <> 0 Then
            MessageBox.Show(str.ToString())
            Return
        End If
        Dim str1 As New StringBuilder
        str1.Append(validated.Validate(txtWebsite, False, validated.StringAll, "Website"))
        If str1.Length <> 0 Then
            MessageBox.Show(str1.ToString())
            Return
        End If
        Dim str2 As New StringBuilder
        str2.Append(validated.Validate(Txt_Vat, False, validated.StringAll, "Remarks"))
        If str2.Length <> 0 Then
            MessageBox.Show(str1.ToString())
            Return
        End If
        Dim str3 As New StringBuilder
        str3.Append(validated.Validate(Txt_Mail, False, validated.EmailAddress, "Email"))
        If str3.Length <> 0 Then
            MessageBox.Show(str3.ToString())
            Return
        End If
        Dim str6 As New StringBuilder
        str6.Append(validated.Validate(Txt_Add, True, validated.StringAll, "txtAddress"))
        If str6.Length <> 0 Then
            MessageBox.Show(str6.ToString())
            Return
        End If

        UpdateSchool("Update tbSchoolInfo set [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected] where [email protected]")
        MainForm.LoadSchoolInfo()
        RefreshGrid()
        frmSelect.Show()
        Me.Close()
    End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Why my databse is not updating ?

#2 RamonRobben   User is offline

  • D.I.C Addict
  • member icon

Reputation: 92
  • View blog
  • Posts: 605
  • Joined: 19-May 14

Re: Why my databse is not updating ?

Posted 05 August 2015 - 06:10 AM

You could try to catch the error:

Try
'your code here
catch ex as Exception

msgbox(ex)

end try


looks like you already have that in your code... weird that i didnt see it the first time.

This post has been edited by RamonRobben: 05 August 2015 - 07:47 AM

Was This Post Helpful? 0
  • +
  • -

#3 demausdauth   User is offline

  • D.I.C Addict
  • member icon

Reputation: 190
  • View blog
  • Posts: 693
  • Joined: 03-February 10

Re: Why my databse is not updating ?

Posted 07 August 2015 - 05:17 AM

Have you tried debugging - put a break point just after the ExecuteNonQuery and see if that returns a value.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1