多用户登录 - 用户添加了哪个文件 [英] Multiuser login - what user added a file
问题描述
喂!所以我有一个应用程序,基本上我可以将文件拖放到一个按钮,然后该文件的信息将显示在标签上。之后,信息将从我的数据库发送到一个表。但是现在我已经创建了一个登录表单,我可以选择是否要使用管理员和普通用户登录。在这里,我为用户构建了一个新表(ID,TypeUser,密码),我现在想要达到的是在我使用某种类型的用户登录后,我添加填充应用程序将识别用户添加了该文件和将它记录在我的数据库中。
这两张桌子都是:
infofile - 文件名
文件类型
文件大小
创建
修改
访问
PcName
和另一张桌子
用户 - ID
TypeUser
密码
如果用户使用管理员帐户登录并添加文件,则会保存以下记录:
文件名 - GTA.exe
文件类型 - .exe
文件大小 - 24145
创建 - 2015年1月6日
修改日期 - 01/06/2015
访问 - 01/06/2015
PcName - MYMACHINE-PC
TypeUser - Administrador
(这将显示在DataGridView上)
这不是我想要的,因为它说这个文件存在,我可以不明白为什么。
我有什么ied:
我试图做一个INSERT
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)"
我试图用INNER JOIN进行查询
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
推荐答案
通过假设引发任何异常将因为文件已存在而混淆实际异常。
而不是输出您自己的错误消息尝试替换MsgBox(Ficheiro existente!)
与MsgBox(e.ToString())
以便我们找出实际例外是。
我不记得这里的实际异常的确切措辞(我不会去重新创建所有东西的麻烦),但是看看
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 replacingMsgBox("Ficheiro existente!")
withMsgBox(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
.Add("@MoveRecycle", SqlDbType.Char).Value = sentRecycle
您没有为@TypeUser提供值,这将产生错误。
You are not supplying a value for @TypeUser and that will generate an error.
这篇关于多用户登录 - 用户添加了哪个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!