在使用vb.net插入新数据之前,如何检查现有数据?
我有一个表是外部_work_duty_details。因此,我想检查用户何时无法插入与现有数据相同的数据。我不知道如何编写代码
:一个要在24/5/2022上申请,直到25/5/2022,但已经以相同的日期应用了它。因此,当单击按钮提交时,显示消息将显示A无法应用。如果现有数据被拒绝或取消,则只能应用它,但是如果它正在待处理或批准,则不能申请。 列确认为状态。 deAfult 0 =待处理。 1 =批准,2 =拒绝,3 =取消。
external_work_duty_details表
id duty_id employee_no UserId employee_dept Reason Start_date End_date Remarks Acknowledgement
48 D2205-00029 1315 800 3 OUTSTATION 2022-05-17 2022-05-19 out test 3
49 D2205-00030 1511 1342 32 COMPANY TRIP 2022-05-23 2022-05-27 trip test 1
50 D2205-00031 1115 127 3 MEETING 2022-05-25 2022-05-25 meet 1
这是我的vb.net代码(编辑代码)
Private Function checkExistingData(ByVal startdate As String, ByVal enddate As String, ByVal intUserid As Integer, ByVal reason As String) As DataTable
Dim dt As New DataTable
Dim strCheck As String = "SELECT * FROM FROM exteral_work_duty_details WHERE Start_Date=@Start_Date, End_Date=@End_Date, UserId=@UserId, Reason=@Reason"
myconn.AddParameter("@Start_Date", MySqlDbType.VarChar)
myconn.SetParameter("@Start_Date", startdate)
myconn.AddParameter("@End_Date", MySqlDbType.VarChar)
myconn.SetParameter("@End_Date", enddate)
myconn.AddParameter("@UserId", MySqlDbType.Int32)
myconn.SetParameter("@UserId", intUserid)
myconn.AddParameter("@Reason", MySqlDbType.String)
myconn.SetParameter("@Reason", reason)
Try
myconn.OpenConnection()
myconn.FillDataTable(dt, strCheck)
myconn.CloseConnection()
myconn.ClearAllParameter()
Catch ex As Exception
myconn.CloseConnection()
myconn.ClearAllParameter()
End Try
Return dt
End Function
I have one table which is external_work_duty_details. So i want to do checking when user cannot inserting the same data as existing data. I have no idea on how to write the code
for example : A want to apply on 24/5/2022 until 25/5/2022 but A already applied it with the same date. so here when A click button submit, display message will appear saying A can't apply. A only can apply it IF the existing data is rejected or cancelled BUT IF it's pending or approved A cannot apply.
Column Acknowledgement is for the status. deafult 0 = pending. 1 = approved, 2 = rejected and 3 = cancelled.
external_work_duty_details Table
id duty_id employee_no UserId employee_dept Reason Start_date End_date Remarks Acknowledgement
48 D2205-00029 1315 800 3 OUTSTATION 2022-05-17 2022-05-19 out test 3
49 D2205-00030 1511 1342 32 COMPANY TRIP 2022-05-23 2022-05-27 trip test 1
50 D2205-00031 1115 127 3 MEETING 2022-05-25 2022-05-25 meet 1
here is my vb.net code (edit code)
Private Function checkExistingData(ByVal startdate As String, ByVal enddate As String, ByVal intUserid As Integer, ByVal reason As String) As DataTable
Dim dt As New DataTable
Dim strCheck As String = "SELECT * FROM FROM exteral_work_duty_details WHERE Start_Date=@Start_Date, End_Date=@End_Date, UserId=@UserId, Reason=@Reason"
myconn.AddParameter("@Start_Date", MySqlDbType.VarChar)
myconn.SetParameter("@Start_Date", startdate)
myconn.AddParameter("@End_Date", MySqlDbType.VarChar)
myconn.SetParameter("@End_Date", enddate)
myconn.AddParameter("@UserId", MySqlDbType.Int32)
myconn.SetParameter("@UserId", intUserid)
myconn.AddParameter("@Reason", MySqlDbType.String)
myconn.SetParameter("@Reason", reason)
Try
myconn.OpenConnection()
myconn.FillDataTable(dt, strCheck)
myconn.CloseConnection()
myconn.ClearAllParameter()
Catch ex As Exception
myconn.CloseConnection()
myconn.ClearAllParameter()
End Try
Return dt
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用VB.NET 6.0.5,Visual Studio 2022社区和Windows 10X64。
我使用此SQL在XAMPP Localhost上创建MySQL Datbase:
然后我使用了此代码并进行了测试并且正在工作。随时适应您的需求。
帮助。
您可以
✽要打开Nuget软件包管理器,连续点击以下四个键,而无需持有 alt alt 键。
alt t n n
Using VB.NET 6.0.5, Visual Studio 2022 Community, and Windows 10 x64.
I used this SQL to create the MySQL datbase on XAMPP Localhost:
Then I used this code and I tested and it's working. Feel free to adjust to fit your needs.
assistance.
You can download the project and test it before you implement it.
✽ To open the NuGet Package Manager, hit the following four keys in succession without holding the Alt key.
AltTNN
解决方案
我终于有了我使用此SQL代码的
,并将其写入商店过程中,对我有用。然后,我将其称为vb.net代码
,
然后在errirfree()函数中称为checkexistingdata()函数
,最后,我在btnsubmitexternalworkderworkdutydetails_click()中调用errirfree()函数。
i finally have the solution
I use this sql code and write it in store procedures
and it works for me. then i call it in my vb.net code like this
and this
Then i call CheckExistingData() function in ErrorFree() function like this
and lastly, i call the ErrorFree() function in btnSubmitExternalWorkDutyDetails_Click()