user6415785
user6415785

Reputation:

Changing the name of a button

So I am trying to make a validation where, for example,

if the user drop into a button a file and it already exists into the database it will displays a message("This file already exists") and it should rename the button name from the name of the file onto the actual name of it.

This is the method that I am calling at the moment of dropping a file into a button and it will change and display what I want.

Private Sub UpdateControls()
        SQLCon = New SqlConnection
        SQLCon.ConnectionString = "........."

        Dim query As String
        query = "SELECT Filename 
                FROM infofile
                WHERE Filename=@Filename"

        If cmdEntrar.Text = query Then
            cmdEntrar.Text = "Open file"
        Else
            cmdEntrar.Text = MeuFicheiro.Name
            cmdEntrar.Width = GetButtonSize(MeuFicheiro.Name)

            lblArraste.Left = cmdEntrar.Left + cmdEntrar.Width + 15
        End If
    End Sub

Because I have a Public Sub where I've called it AddFile and there I will add a bunch of things from a file(name, extension, etc) into my database. But if I add a file that already exists it will clear all the labels from layout and change the name of the button to the original. But that part is not working.

This is the piece of code where the validation is made

 Public Sub AddFile(Filename As String, Filetype As String, Filesize As String, Created As Date, Modified As Date, Access As Date, PcName As String)
    SQLCon = New SqlConnection
    SQLCon.ConnectionString = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\MIGG-PC\Documents\Visual Studio 2015\Projects\TrashCollection\TrashCollection\TrashDB.mdf;Integrated Security=True;Connect Timeout=30"
    Try
        Dim strInsert As String = "INSERT INTO INFOFILE (Filename,Filetype,Filesize,Created,Modified,Access,PcName) " &
                                  "VALUES (" &
                                  "'" & Filename & "'," &
                                  "'" & Filetype & "'," &
                                  "'" & Filesize & "'," &
                                  "'" & Access & "'," &
                                  "'" & Created & "'," &
                                  "'" & Modified & "'," &
                                  "'" & PcName & "')"
        SQLCon.Open()
        SqlCmd = New SqlCommand(strInsert, SQLCon)

        SqlCmd.ExecuteNonQuery()

        SQLCon.Close()
    Catch ex As Exception
        MsgBox("Ficheiro existente!")
        pathTextBox.Clear()
        lblName.Text = String.Empty
        lblType.Text = String.Empty
        lblSize.Text = String.Empty
        lblCreated.Text = String.Empty
        lblModify.Text = String.Empty
        lblAccess.Text = String.Empty
        lblKB.Text = String.Empty
        nomePcLbl.Text = String.Empty
        pbIcon.Image = Nothing
        pbGreenDot.Image = Nothing
        pbRedDot.Image = Nothing
    End Try
End Sub

And I want to add in this exception the possibility to change the button text to the original one

Any solution for That? Thanks in Advance..

Upvotes: 0

Views: 121

Answers (1)

user6344551
user6344551

Reputation:

You should be manipulating the page load where the controls text are cleared.

Would be more useful if you share the code.

Upvotes: 1

Related Questions