29-03-14, 09:25 PM
السلام عليكم
بالنسبة للقسم الثاني من السؤال
في الحدث KeyDown
اكتب هذا الكود
وفي الحدث Validated
اكتب هذا الكود
بالنسبة للقسم الثاني من السؤال
في الحدث KeyDown
اكتب هذا الكود
كود :
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
TextBox2.Focus()
End If
End Subوفي الحدث Validated
اكتب هذا الكود
كود :
Private Sub TextBox1_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Validated
هذا الكود غرضه التأكد من السجل المدني موجود اوغير موجود
Dim con As New SqlConnection
Dim cmd As New SqlCommand
con.Close()
con.ConnectionString = "Server=your server;Database=your database;Integrated Security=true"
cmd.Connection = con
con.Open()
cmd.Parameters.Clear()
cmd.CommandText = "Select * from your table where Number=@un"
cmd.Parameters.Add("@un", SqlDbType.NVarChar, 50).Value = TextBox1.Text
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.HasRows = True Then
MessageBox.Show("هذا السجل موجود", "تحذير", MessageBoxButtons.OK, MessageBoxIcon.Warning)
TextBox1.Focus()
TextBox1.SelectionStart = 0
con.Close()
End If
End Sub
