Hi, I hv vb.net applivcation.
I have following CODE1 to save data & to prevent duplicate data entry into table.
The following code I put in button save event.
However I want to put this CODE2 in perticluar textbox e.g. here SpecimenNoTextBox. so that when the user enter duplicate SpecimenNo.it says "Specimen No. already exist".
How can i do this?
CODE1
If SpecimenNoTextBox.Text = "" Then
MsgBox("Enter")
Else
Dim cmd As New OleDbCommand
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\data\Histopathology New.accdb")
con.Open()
Dim cmdlogin As New OleDbCommand(("SELECT SpecimenNo FROM HPReport"), con)
Dim dalogin As New OleDbDataAdapter
Dim dslogin As New DataSet
dalogin.SelectCommand = cmdlogin
cmdlogin.ExecuteNonQuery()
dslogin.Clear()
dalogin.Fill(dslogin, "HPReport")
If dslogin.Tables(0).Rows.Count > 0 Then
Dim i As Integer = 0
While i < dslogin.Tables(0).Rows.Count
If SpecimenNoTextBox.Text = dslogin.Tables(0).Rows(i).Item(0).ToString Then
MsgBox("ID Already exist")
GoTo Line1
Else
End If
i = i + 1
End While
Else
MsgBox("No Data Exist")
End If
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into HPReport(ID,Status,RegNo,PatientName,Age,Sex,InchargeUnitDr,Ward,SColleDate,SReceDate,SIDNo,SpecimenNo) values ('" & IDTextBox.Text & "','" & StatusComboBox.Text & "','" & RegNoTextBox.Text & "','" & PatientNameTextBox.Text & "','" & AgeTextBox.Text & "','" & SexComboBox.Text & "','" & InchargeUnitDrComboBox.Text & "','" & WardComboBox.Text & "','" & SColleDateTextBox.Text & "','" & SReceDateTextBox.Text & "','" & SIDNoTextBox.Text & "','" & SpecimenNoTextBox.Text & "',)"
cmd.ExecuteNonQuery()
MsgBox("Added Successfuly")
SpecimenNoTextBox.Clear()
autogenerate_ID()
Line1:
End If
End Sub
CODE2
Dim cmd As New OleDbCommand
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\data\Histopathology New.accdb")
con.Open()
Dim cmdlogin As New OleDbCommand(("SELECT SpecimenNo FROM HPReport"), con)
Dim dalogin As New OleDbDataAdapter
Dim dslogin As New DataSet
dalogin.SelectCommand = cmdlogin
cmdlogin.ExecuteNonQuery()
dslogin.Clear()
dalogin.Fill(dslogin, "HPReport")
If dslogin.Tables(0).Rows.Count > 0 Then
Dim i As Integer = 0
While i < dslogin.Tables(0).Rows.Count
If SpecimenNoTextBox.Text = dslogin.Tables(0).Rows(i).Item(0).ToString Then
MsgBox("ID Already exist")
GoTo Line1
Else
End If
i = i + 1
End While
Else
MsgBox("No Data Exist")
End If
Line1: