I want the number not to be repeated in the database. One of the programmers here wrote me this code and the code works. There is a small obstacle that if it is taken today, it will not be taken tomorrow or on a new date. It appears to me that it exists in the database on a previous date and not a new date.
I want that if taken today at breakfast, the number will not be repeated at breakfast, and if taken at lunch, it will not be repeated and taken tomorrow.
Thanks to all.
What I have tried:
Dim conn As SqlConnection = New SqlConnection_
("Data Source=DESKTOP-NO2IM8B\SQLEXPRESS;_
Initial Catalog=Barcode;User ID=sa;Password=P@ssw0rd")
conn.Open()
Dim cmd2 As SqlCommand = New SqlCommand_
("SELECT sale_id FROM Table_1 WHERE _
Meal_time = @Meal_time AND sale_id = @sale_id ", conn)
cmd2.Parameters.AddWithValue("Meal_time", DropDownList2.Text)
cmd2.Parameters.AddWithValue("@sale_id", txtUserName.Text)
Dim myreader As SqlDataReader = cmd2.ExecuteReader()
If myreader.Read() Then
conn.Close()
Dim message As String = _
"الطالب موجود بالفعل+The student already exists"
Dim sb As New System.Text.StringBuilder()
sb.Append("")
sb.Append("window.onload=function(){")
sb.Append("alert('")
sb.Append(message)
sb.Append("')};")
sb.Append("")
ClientScript.RegisterClientScriptBlock_
(Me.GetType(), "alert", sb.ToString())
Else
conn.Close()
Dim cmd As SqlCommand = New SqlCommand_
("INSERT INTO Table_1(sale_id,building,Meal_time,date) _
VALUES(@sale_id,@building,@Meal_time,@date)", conn)
cmd.Parameters.AddWithValue("sale_id", txtUserName.Text)
cmd.Parameters.AddWithValue("building", DropDownList1.Text)
cmd.Parameters.AddWithValue("Meal_time", DropDownList2.Text)
cmd.Parameters.AddWithValue("date", Now)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Dim message As String = "تم الادخال+_
The student number has been entered"
Dim sb As New System.Text.StringBuilder()
sb.Append("")
sb.Append("window.onload=function(){")
sb.Append("alert('")
sb.Append(message)
sb.Append("')};")
sb.Append("")
ClientScript.RegisterClientScriptBlock_
(Me.GetType(), "alert", sb.ToString())
End If
End Sub