6 Replies - 68523 Views - Last Post: 27 January 2008 - 02:04 AM Rate Topic: -----

#1 cimpercee  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 127
  • Joined: 10-August 06

binding source, how to bind?

Post icon  Posted 14 August 2007 - 10:18 AM

how do you bind a bindingsource created on class to a textbox?

i want to bind a specific field, but i dont know how because database is retrieve at runtime.
Is This A Good Question/Topic? 0
  • +

Replies To: binding source, how to bind?

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: binding source, how to bind?

Posted 15 August 2007 - 05:17 AM

To bind a single item in the BindingSource to a TextBox use this

TextBox1.Text = YourBindingSource("YourFieldName").ToString



Of course replace YourBindingSource with the name of your BindingSource Object, and YourFieldName with the name of the field you're looking for.

If there are multiple records returned and you have multiple textboxes to fill then do it in a loop (doing it this way your textboxes should be names YourName_1, YourName_2, etc...)

For i As Integer = 0 To YourBindingSource.Count - 1
TextBox_ & i & .Text = YourBindingSource(i)("YourFieldName").ToString
Next



This should at least get you started in the right direction :)

Happy Coding!
Was This Post Helpful? 0
  • +
  • -

#3 cimpercee  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 127
  • Joined: 10-August 06

Re: binding source, how to bind?

Posted 17 August 2007 - 08:31 PM

Hi,

i get errors

"conversion from string "Username" to type integer is not valid.

my line of code

mytextbox.text = mybindingsource("Username").tostring
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: binding source, how to bind?

Posted 17 August 2007 - 08:42 PM

Try this

TextBox1.DataBindings.Add("Text",MyBindingSource,"Username")



Doing this you're using the DataBindings property of the control to pull the username value from the bindingsource object. Hope this helps :)

Happy Coding!
Was This Post Helpful? 1
  • +
  • -

#5 cimpercee  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 127
  • Joined: 10-August 06

Re: binding source, how to bind?

Posted 17 August 2007 - 09:04 PM

it works... thank you sir
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: binding source, how to bind?

Posted 17 August 2007 - 09:04 PM

No problem cimpercee, thats what we're here for :) Glad I could help :^:

<edit>No need to call me sir :)</edit>

This post has been edited by PsychoCoder: 17 August 2007 - 09:05 PM

Was This Post Helpful? 0
  • +
  • -

#7 flodi  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 16
  • Joined: 20-January 08

Re: binding source, how to bind?

Posted 27 January 2008 - 02:04 AM

hi
i would like to make binding to only the field that i search by
and here is my search code
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()
					SqlConnection1.Close()
				End If
			End If
		End If



and here is my 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



its binding succsefully but what i want is to only binding the data that comes from my search
Was This Post Helpful? 1

Page 1 of 1