Results 1 to 3 of 3

Thread: BindingContext

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    58

    BindingContext

    Dear Experts
    I use following codes to display data.
    Next & Back buttons work fine, but when I enter some sno into textbox1 then it displays nothing
    Codes on textbox1 lostfocus
    Code:
       Me.ds.Tables("employees").Rows.Find(Me.TextBox1.Text)
    Codes in Form Load
    Code:
    Dim sql = "select * from employees"
            Dim da As New SqlClient.SqlDataAdapter(sql, con)
            ds.Clear()
            da.Fill(ds, "employees")
            TextBox1.DataBindings.Add("text", ds.Tables("employees"), "sno")
            TextBox2.DataBindings.Add("text", ds.Tables("employees"), "Name")
            TextBox3.DataBindings.Add("text", ds.Tables("employees"), "City")
            TextBox4.DataBindings.Add("text", ds.Tables("employees"), "Phone")
            Dim colpk(0) As DataColumn
            colpk(0) = ds.Tables(0).Columns("sno")
            ds.Tables(0).PrimaryKey = colpk
    Codes on Next Button
    Code:
    Me.BindingContext(ds.Tables("employees")).Position += 1
    Codes on Back Button
    Code:
    Me.BindingContext(ds.Tables("employees")).Position -= 1
    How to display relevant data against column sno given in textbox1
    Please help

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: BindingContext

    don't use textbox1_lostfocus
    try textbox1_textchanged instead

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: BindingContext

    You shouldn't need to use BindingContext in VB 2008. Bind your data via a BindingSource and then that provides the functionality that you had to get from several other sources previously, including the CurrencyManager returned by BindingContext. The BindingSource class has MoveNext and MovePrevious methods. That's also safer because I think your code will throw an exception when you try to go beyond either limit of the data.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width