如何跟踪或限制多个上传到SQL Server数据库?

我是新手开发工作,我正在上一个macros上载button,允许用户上传(插入语句)他们的数据到我们的SQL Server数据库的Excel工作表。

只有7个用户。 如果多次点击上传button,我会如何限制上传到我们的数据库的数量?

我们正在尝试让所有7个用户将其提交给负责人进行点击上传,但只是想尽量减less用户错误。 任何帮助非常感谢谢谢。

通过正确构build解决scheme可以有多种方法来实现这一点。 最明显的方法是devise你的数据库模式,使得devise不允许重复。

主键应该是你的朋友在这里。 确保问题表上的主键是正确定义的。

所以,即使所有7个用户尝试插入任何次数,重复插入的问题都可以被缓解。

将每个用户的上传数量存储在一个隐藏表格中,并在VBA中使用类似的内容:

Sub Upload() Dim uploadWS As Worksheet Dim userRow As Range Const MAX_UPLOADS As Byte = 3 '// Change to whatever you want Set uploadWS = Sheets("Upload Data") '// lets assume userID in column A and number of uploads in column B Set userRow = uploadWS.Range("A:A").Find(Environ$("USERNAME")) If userRow Is Nothing Then With uploadWS.Range("A" & uploadWS.Rows.Count).End(xlUp).Offset(1, 0) .Value = Environ$("USERNAME") .Offset(0, 1).Value = 1 End With '// Code for uploading here Else With userRow.Offset(0, 1) If .Value <= MAX_UPLOADS Then .Value = .Value + 1 Else MsgBox "You have exceeded max allowed uploads, please contact admin.", vbOkOnly + vbCritical, "Error" Exit Sub End If End With '// Code for uploading here End If End Sub