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
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
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
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