似乎无法弄清楚如何检查唯一的员工ID号。我知道验证必须以表格加载,只是不确定如何去做。
Public Class Form1
Dim filename As String
Dim dataFile As System.IO.File
Dim dataWrite As System.IO.StreamWriter
''LOADING AND WRITE TO TEXT DOCUMENT
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'asks user for file name
filename = InputBox("Enter output file name")
If IO.File.Exists(filename) Then
dataWrite = IO.File.AppendText(filename)
Else
MessageBox.Show("filename does not exist")
filename = InputBox("Enter output file name")
dataWrite = IO.File.CreateText(filename)
End If
cboDepart.Items.Add("Accounting")
cboDepart.Items.Add("Administration")
cboDepart.Items.Add("Marketing")
cboDepart.Items.Add("MIS")
cboDepart.Items.Add("Sales")
End Sub
'------
Public EMPLOYEEIDS As String
Dim employeeID1 As ServerData()
Dim employeeID2 As ServerData()
Dim reader As String = My.Computer.FileSystem.ReadAllText("servers.lst")
Dim s() As String
Dim Totalemployeeids As String = CStr(reader.Length)
Dim x As Integer = 0
Dim myArray As String() = reader.Split("|"c)
For x = 1 To Totalemployeeids
employeeID1(x).ServerName = myArray(0)
employeeID2(x).IDname = myarray(0)
Form1_load.ListBox1.Items.Add(Servers(x).ServerName)
x += 1
Next
Structure ServerData
End Structure
End Class
答案 0 :(得分:0)
您通常不从客户端插入唯一ID。相反,它由数据库服务器自动插入。如果您需要显示插入的ID,有一种方法可以检索插入的ID(也可以作为成功插入记录的确认):
SELECT SCOPE_IDENTITY()
这个答案中显示了一个例子:
在客户端,您需要实现除ID之外的所有内容的插入,在这种情况下,您无需检查唯一性。提交时可能存在其他验证问题(唯一键冲突,数据类型不匹配) - 确保捕获异常并将其显示给用户。