21-02-14, 06:01 PM
frmNew.vb
كود :
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If txtName.Text = Nothing Then
MsgBox("يجب إدخال الاسم", MsgBoxStyle.Critical, "عذراً")
txtName.Focus()
Else
If ExistName(txtName.Text) Then '<<<<<<<<<<<<<<<<<<<<<<<<<
MsgBox("الاسم موجود مسبقاً", MsgBoxStyle.Critical, "عذراً") '<<<<<<<<<<<<<<<<<<<<<<<<<
Exit Sub '<<<<<<<<<<<<<<<<<<<<<<<<<
Else
SaveData() '<<<<<<<<<<<<<<<<<<<<<<<<<
End If
MsgBox("تم تخزين البيانات بنجاح", MsgBoxStyle.Information, "ألف مبروك")
txtName.Text = Nothing
txtName.Focus()
End If
End Sub
Private Function ExistName(ByVal theName As String) As Boolean '<<<<<<<<<<<<<<<<<<<<<<<<<<
Dim ExistDataSQl As String = "SELECT [TheName] FROM [TheTable] WHERE [TheName]=@TheName"
Dim ExistDataCMD As New OleDbCommand(ExistDataSQl, Con)
ExistDataCMD.Parameters.AddWithValue("@TheName", theName)
Dim ExistDataADP As New OleDbDataAdapter(ExistDataCMD)
If ExistDataADP.Fill(New DataTable) > 0 Then Return True
End Function


