بسم الله الرحمن الرحيم
اخوانى عندى مشكلة فى كود البحث فى قواعد بيانات sql
حيث عندى البحث بالاسم يطلع لى خطأ وهو ساعدونى
ExecuteReader: Connection property has not been initialized
sqlstatment = " "
sql1 = " "
Dim firstcont As Boolean = True
If txtquery1.Text <> " " Then
If firstcont = False Then
sqlstatment = sqlstatment & " patient . id like '%" & txtquery1.Text & "%'"
Else
firstcont = False
sqlstatment = sqlstatment & " patient . id 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 ")
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")
sqlcon.Close()
Else
lblerror.BackColor = Color.Red
lblerror.BackColor = Color.White
lblerror.Text = "السجل غير موجود "
If sqlstatment = ConnectionState.Open Then
sqlcon.Close()
End If
End If
End Sub
اخوانى عندى مشكلة فى كود البحث فى قواعد بيانات sql
حيث عندى البحث بالاسم يطلع لى خطأ وهو ساعدونى
ExecuteReader: Connection property has not been initialized
sqlstatment = " "
sql1 = " "
Dim firstcont As Boolean = True
If txtquery1.Text <> " " Then
If firstcont = False Then
sqlstatment = sqlstatment & " patient . id like '%" & txtquery1.Text & "%'"
Else
firstcont = False
sqlstatment = sqlstatment & " patient . id 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 ")
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")
sqlcon.Close()
Else
lblerror.BackColor = Color.Red
lblerror.BackColor = Color.White
lblerror.Text = "السجل غير موجود "
If sqlstatment = ConnectionState.Open Then
sqlcon.Close()
End If
End If
End Sub
