Click here to Skip to main content
15,881,844 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey! So I have an application where basically I am able to drag and drop a file into a button and then the info of that file will be shown on labels. After it that info will be sent to a table from my database. But now I've created a login form where I can choose if I want to log in with administrator and normal user. Here I built a new table for users where I got(ID, TypeUser, Password), what I want to reach now is after I log in with a type of user and I add a fill the application will recognize what user added that file and will record it on my database.

This is the both tables:

infofile - Filename
Filetype
Filesize
Created
Modified
Access
PcName

And the other table

users - ID
TypeUser
Password

If users log in with Administrator account and add a file it will be save the record like:

Filename - GTA.exe
Filetype - .exe
Filesize - 24145
Created - 01/06/2015
Modified - 01/06/2015
Access - 01/06/2015
PcName - MYMACHINE-PC
TypeUser - Administrador
(This will be shown on a DataGridView)

This is not returning what I want because it says that this file exists and I can't understand why.

What I have tried:

I've tried to making an INSERT
SQL
INSERT INTO infofile(Filename, Filetype, Filesize, Created, Modified, Access, PcName, TypeUser)
                                        VALUES(@Filename, @Filetype, @Filesize, @Created, @Modified, @Access, @PcName, @TypeUser)"

I've tried to making a query with INNER JOIN
SQL
SELECT infofile.Filename, users.TipoUtilizador
FROM infofile
INNER JOIN users
ON infofile.Filename=users.Filename
ORDER BY infofile.Filename


This is the code where "That file already exists!" displays

VB
Sub AddFile()
        SQLCon = New SqlConnection
        SQLCon.ConnectionString = "....."
        Dim sentRecycle As Boolean = SentToRecycle(MeuFicheiro.ToString)
        Try
            Query = "INSERT INTO infofile(Filename, Filetype, Filesize, Created, Modified, Access, PcName, TypeUser)
                                        VALUES(@Filename, @Filetype, @Filesize, @Created, @Modified, @Access, @PcName, @TypeUser)"
            SQLCon.Open()
            SqlCmd = New SqlCommand(Query, SQLCon)

            With SqlCmd.Parameters
                .Add("@Filename", SqlDbType.Char).Value = lblName.Text
                .Add("@Filetype", SqlDbType.Char).Value = lblType.Text
                .Add("@Filesize", SqlDbType.Int).Value = lblSize.Text
                .Add("@Created", SqlDbType.Char).Value = lblCreated.Text
                .Add("@Modified", SqlDbType.Char).Value = lblModify.Text
                .Add("@Access", SqlDbType.Char).Value = lblAccess.Text
                .Add("@PcName", SqlDbType.Char).Value = nomePcLbl.Text
                .Add("@MoveRecycle", SqlDbType.Char).Value = sentRecycle
            End With
            Carregar()

            SqlCmd.ExecuteNonQuery()

            SQLCon.Close()
        Catch ex As Exception
            MsgBox("Ficheiro existente!")
            ClearFields()
        End Try
    End Sub
Posted
Updated 24-Jun-16 0:04am
v3
Comments
CHill60 24-Jun-16 5:18am    
So what is your actual question or problem?
Member 12490691 24-Jun-16 5:40am    
I've just edited it. Sorry
CHill60 24-Jun-16 5:52am    
Which line of code says "this file exists"? Not any of the code you have posted so far!
Kats2512 24-Jun-16 5:33am    
no, we don't know what is meant by this. Please use the improve question link and clarify what it is that you are actually looking for assistance with.
Member 12490691 24-Jun-16 5:43am    
Already edited the question

1 solution

You are obfuscating the actual exception by assuming any exception raised will be because the file already exists.
Instead of outputting your own error message try replacing MsgBox("Ficheiro existente!") with MsgBox(e.ToString()) so that we find out what the actual exception is.

I can't remember the exact wording of the actual exception here (and I'm not going to go the trouble of recreating everything), however look at
Query = "INSERT INTO infofile(Filename, Filetype, Filesize, Created, Modified, Access, PcName, TypeUser)
                            VALUES(@Filename, @Filetype, @Filesize, @Created, @Modified, @Access, @PcName, @TypeUser)"

but when you are adding parameters you have
C#
.Add("@MoveRecycle", SqlDbType.Char).Value = sentRecycle

You are not supplying a value for @TypeUser and that will generate an error.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900