الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

التنقل بين السجلات المبحوث عنها فقط_رسالة خطاء بالكود

مغلق
بدأه flodi في 27 يناير 2008 · 3 رد · 812 مشاهدة · في ADO.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

الكود التالي يقوم بالبحث واظهار النتائج على صناديق النصوص في الفورم

وارغب بالاضافة الى ذلك ان يقوم زري التحكم (التالي) و (السابق) باظهار باقي نتائج البحث فقط

وقمت بعمل binding الا انه يظهر لي رسالة خطاء واليكم الكود

If RadioButton1.Checked = True Then
			If nametext.Text = "" Then
				MsgBox("خطاء في البحث !! الرجاء ادخال اسم الموظف")
				Call cancel()
				Call clear()
			Else
				SqlCommand4.Parameters("@tech_name").Value = nametext.Text
				Dim read As SqlClient.SqlDataReader
				SqlConnection1.Open()
				read = SqlCommand4.ExecuteReader
				If Not read.Read Then
					MsgBox("الاسم غير موجود")
					read.Close()
					SqlConnection1.Close()
					Call cancel()
					Call clear()
				Else
					TextBox1.Text = read.Item("id")
					nametext.Text = read.Item("tech_name")
					ComboBox1.Text = read.Item("tech_sec")
					ComboBox2.Text = read.Item("tech_level")
					usertext.Text = read.Item("tech_user_name")
					passtext.Text = read.Item("tech_password")
					pass1text.Text = read.Item("tech_rpassword")
					ComboBox3.Text = read.Item("user_type")
					read.Close()
					da = New SqlDataAdapter("select * from client where (tech_name LIKE @tech_name + N'%')", SqlConnection1)
					da.FillSchema(ds, SchemaType.Source, "cilent")
					da.Fill(ds, "client")
					SqlConnection1.Close()
					bind.DataSource = ds
					bind.DataMember = "client"
					SqlConnection1.Close()
					Me.TextBox1.DataBindings.Add(New Binding("text", bind, "id", True))
					Me.nametext.DataBindings.Add(New Binding("text", bind, "tech_name", True))
					Me.ComboBox1.DataBindings.Add(New Binding("text", bind, "tech_sec", True))
					Me.ComboBox2.DataBindings.Add(New Binding("text", bind, "tech_level", True))
					Me.usertext.DataBindings.Add(New Binding("text", bind, "tech_user_name", True))
					Me.passtext.DataBindings.Add(New Binding("text", bind, "tech_password", True))
					Me.pass1text.DataBindings.Add(New Binding("text", bind, "tech_rpassword", True))
					Me.ComboBox3.DataBindings.Add(New Binding("text", bind, "user_type", True))
				End If
			End If
		End If

ورسالة الخطاء هي كالتالي

Must declare the variable '@tech_name'

وكود زري السابق والتالي

bind.MoveNext()

bind.MovePrevious()

علماً بان البرنامج ينفذ الربط او binding بشكل صحيح ولكن لكل البيانات بالجدول

كود binding الجدول

Dim ds As New DataSet
	Dim da As New SqlDataAdapter
	Dim bind As New BindingSource
	Private Sub Users_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		SqlConnection1.Open()
		da = New SqlDataAdapter("select * from client", SqlConnection1)
		da.FillSchema(ds, SchemaType.Source, "cilent")
		da.Fill(ds, "client")
		SqlConnection1.Close()
		bind.DataSource = ds
		bind.DataMember = "client"
		Me.TextBox1.DataBindings.Add(New Binding("text", bind, "id", True))
		Me.nametext.DataBindings.Add(New Binding("text", bind, "tech_name", True))
		Me.ComboBox1.DataBindings.Add(New Binding("text", bind, "tech_sec", True))
		Me.ComboBox2.DataBindings.Add(New Binding("text", bind, "tech_level", True))
		Me.usertext.DataBindings.Add(New Binding("text", bind, "tech_user_name", True))
		Me.passtext.DataBindings.Add(New Binding("text", bind, "tech_password", True))
		Me.pass1text.DataBindings.Add(New Binding("text", bind, "tech_rpassword", True))
		Me.ComboBox3.DataBindings.Add(New Binding("text", bind, "user_type", True))
			Label13.Text = username
	End Sub

فاين سبب وجود هذا الخطاء

شكراً

#3

شكراً اخي الفاضل

الا يعتبر هذا تعريف للمتغير

da = New SqlDataAdapter("select * from client where (tech_name LIKE @tech_name + N'%')", SqlConnection1)

واذا كانت لا فكيف يتم تعريفه؟وهل هناك خطاء اخر بالكود؟

#4

أختي فلودي يجب أن تضيفي أي معاملات تضيفيها في الاستعلام في مجموعة المعالات كالتالي

أي بدلا من

SqlCommand4.Parameters("@tech_name").Value = nametext.Text

تضعي

SqlCommand4.Parameters.add("@tech_name",string).Value = nametext.Text

أو

SqlCommand4.Parameters.addwithValue("@tech_name") = nametext.Text

أنا الرجل الضرب الذي تعرفونه***خشاش كرأس الحية المتوقد

لوكنت وغلاً في الرجال لضرني**** حسن جرائتي ومقتدي

منتديات طريق الهداية

هذا الموضوع مغلق.

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…