اخوانى عندى كود للبحث فى قاعدة البيانات بالاسم
انا اعرف انو البحث لازم يكون بحقل لا يتكرر مثل الرقم القومى مثلا ولكن مشروعى ليس فيه شى يتم البحث من خلاله إلا الاسماء
الكود شغال ولكن ليس بصورة 100% لانه يجلب اقرب اسم ولا يعطى الاسم الصحيح
يعنى مثلا اذا اردت ان ابحث عن (محمد على احمد ) اذا كتبت على مثلا
يعطينى هذا الجواب
فما الحل ؟
انا اعرف انو البحث لازم يكون بحقل لا يتكرر مثل الرقم القومى مثلا ولكن مشروعى ليس فيه شى يتم البحث من خلاله إلا الاسماء
الكود شغال ولكن ليس بصورة 100% لانه يجلب اقرب اسم ولا يعطى الاسم الصحيح
يعنى مثلا اذا اردت ان ابحث عن (محمد على احمد ) اذا كتبت على مثلا
يعطينى هذا الجواب
فما الحل ؟
PHP كود :
[Imports System.Data.SqlClient
Imports System.Globalization
Public Class ser
Dim sqlcon As New SqlConnection(" data source = ABDALRAHMAN-PC\SQLEXPRESS; initial catalog = medical ; integrated security = true")
Dim sqlstatment As String
Dim sql1 As String
Dim winclass As New Class1
Private Sub ser_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
winclass.Fillcombobox(cbojob, " jobs", "jobname", "jobid", " ")
cbojob.SelectedIndex = -1
End Sub
Private Sub btnquery1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnquery1.Click
btnquery1.Enabled = False
btnnewquery1.Enabled = True
If txtquery1.Text.Trim = "" Then
MsgBox("ادخل الاسم للبحث ", MsgBoxStyle.Exclamation)
txtquery1.Focus()
lblerror.Text = (" ادخل الاسم للبحث ")
lblerror.ForeColor = Color.Red
Exit Sub
End If
If sqlcon.State = ConnectionState.Open Then
sqlcon.Close()
End If
'---------------------------------------------------
sqlstatment = " "
sql1 = " "
Dim firstcont As Boolean = True
If txtquery1.Text <> " " Then
If firstcont = False Then
sqlstatment = sqlstatment & " patient.name like '%" & txtquery1.Text & "%'"
Else
firstcont = False
sqlstatment = sqlstatment & " patient.name like '%" & txtquery1.Text & "%'"
End If
End If
sqlcon.Open()
sql1 = " Select * from patient where " & sqlstatment
Dim cmd As New SqlCommand(sql1)
cmd.Connection = sqlcon
Dim dr As SqlDataReader = cmd.ExecuteReader
If dr.HasRows Then
dr.Read()
txtrec1.Text = dr.Item("id")
txtren.Text = dr.Item("name")
txtname.Text = dr.Item("name")
txtid.Text = dr.Item("id")
cbojob.SelectedValue = dr.Item("jobid")
txtdate.MyText = dr.Item("date")
txttel.Text = dr.Item("tel")
txtphone.Text = dr.Item("phone")
txtaddress.Text = dr.Item("address")
txtcomment.Text = dr.Item("comments")
cboage.SelectedText = dr.Item("age")
cbogender.SelectedText = dr.Item("gender")
cbomerital.SelectedText = dr.Item("merital")
sqlcon.Close()
btnenabled1.Enabled = True
Else
lblerror.BackColor = Color.Red
lblerror.ForeColor = Color.White
lblerror.Text = "الاسم غير موجود "
sqlcon.Close()
End If
End Sub
Private Sub btnnewquery1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnewquery1.Click
btnquery1.Enabled = True
btnnewquery1.Enabled = False
cleartext()
'btnsaveupdate1.Enabled = True
sqlcon.Open()
End Sub
Private Sub cleartext()
txtname.Text = " "
txtquery1.Text = " "
txtid.Text = " "
txtaddress.Text = " "
txtcomment.Text = " "
txtdate.MyDay = " "
txtdate.MyMonth = " "
txtdate.MyYear = " "
txttel.Text = " "
txtphone.Text = " "
cboage.Text = " "
cbogender.Text = " "
cbojob.SelectedIndex = -1
cbomerital.Text = " "
lblerror.Visible = False
End Sub
Private Sub enabledtext()
txtname.Enabled = True
txtid.Enabled = True
txtdate.Enabled = True
txtaddress.Enabled = True
txtcomment.Enabled = True
txtphone.Enabled = True
txttel.Enabled = True
cboage.Enabled = True
cbogender.Enabled = True
cbojob.Enabled = True
cbomerital.Enabled = True
sqlcon.Close()
End Sub
Private Sub btnenabled1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnenabled1.Click
enabledtext()
btnsaveupdate1.Enabled = True
End Sub
Private Sub btnsaveupdate1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsaveupdate1.Click
Dim updateok As Boolean = winclass.SQLExciute(" update patient set name= '" & txtname.Text & "',comments='" & txtcomment.Text & "' where id= " & txtrec1.Text & "")
If updateok = True Then
lblerror.Text = (" تمت عملية تعديل البيانات ")
lblerror.BackColor = Color.Green
lblerror.ForeColor = Color.White
btnsaveupdate1.Enabled = False
Else
MsgBox("خطأ فى عملية تعديل البيانات ", MsgBoxStyle.Critical)
End If
End Sub
End Class]