Results 1 to 5 of 5
  1. #1

    Default databinding in listbox using vb.net 2005


    hello bro,

    I have question regarding my codes here:
    this code is working:
    private void btnload_Click(object sender, EventArgs e)
    {

    conn.Open();
    ds = new DataSet();
    cmd = new OleDbCommand("Select Ip from IP", conn);

    da = new OleDbDataAdapter(cmd);
    da.Fill(ds,"IP");
    lstip.DataSource = ds.Tables["IP"];
    lstip.DisplayMember = "Ip";
    conn.Close();

    }
    private void lstip_SelectedIndexChanged(object sender, EventArgs e)
    {

    BindaData();

    }

    This is not working: I want to bind the data from listboox bro, inig click nako sa items from listboox mo display unta sa mga txtbox iyang remaining colums. thank you so much.
    private void BindaData()
    {

    this.txtname.DataBindings.Clear();
    this.txtdepartment.DataBindings.Clear();
    this.txtpcname.DataBindings.Clear();
    this.txtremarks.DataBindings.Clear();

    this.lstip.DataSource = ds.Tables["IP"];
    this.txtname.DataBindings.Add("Text", ds,"User");
    this.txtdepartment.DataBindings.Add("Text", ds, "IP.Department");
    this.txtpcname.DataBindings.Add("Text", ds, "IP.ComputerName");
    this.txtremarks.DataBindings.Add("Text", ds, "IP.Remarks");
    }
    private void BindaData()

    conn.Open();
    cmd = new OleDbCommand("Select * from IP Where Ip = ' " + this.lstip.SelectedItem + " ' ", conn);
    dr = cmd.ExecuteReader();

    while(dr.Read())
    {

    this.txtdepartment.Text = dr[1].ToString();
    this.txtname.Text = dr[2].ToString();
    this.txtpcname.Text = dr[3].ToString();
    this.txtremarks.Text = dr[4].ToString();
    }
    dr.Close();
    conn.Close();

  2. #2
    First fragment:
    Adding DataBindings takes binding object as parameter so syntax should be


    this.txtname..DataBindings.Add( new Binding("Text", ds, "IP.Department"));



    private void BindaData()
    {

    this.txtname.DataBindings.Clear();
    this.txtdepartment.DataBindings.Clear();
    this.txtpcname.DataBindings.Clear();
    this.txtremarks.DataBindings.Clear();

    this.lstip.DataSource = ds.Tables["IP"];
    this.txtname.DataBindings.Add("Text", ds,"User");
    this.txtdepartment.DataBindings.Add("Text", ds, "IP.Department");
    this.txtpcname.DataBindings.Add("Text", ds, "IP.ComputerName");
    this.txtremarks.DataBindings.Add("Text", ds, "IP.Remarks");
    }


    //what are the codes below for?

    private void BindaData()

    conn.Open();
    cmd = new OleDbCommand("Select * from IP Where Ip = ' " + this.lstip.SelectedItem + " ' ", conn);
    dr = cmd.ExecuteReader();

    while(dr.Read())
    {

    this.txtdepartment.Text = dr[1].ToString();
    this.txtname.Text = dr[2].ToString();
    this.txtpcname.Text = dr[3].ToString();
    this.txtremarks.Text = dr[4].ToString();
    }
    dr.Close();
    conn.Close();

  3. #3
    @trojan_vaughn, thanks bro, private void bindaData() ako rana gihimo as an alternative code to bind a data kay d man gud mo work ang first code nako, so im trying to use datareader, so d japon mo work man gud, naka try naman ko ug use sa imong suggested code bro, pero still doesnt work ambot lang kaha sa 2008 na visual studio, 2005 man gud akong gamit karon. lamat bro.

  4. #4
    Way blema peterparker!

    if you want to use data reader and expecting 1 row in the resultset i think you should use

    if(dr.Read())
    {
    // code here.
    }

    But if the bindings work, then no need to do this.

  5. #5
    ang akong value sa listbox bro d man ma capture sa akong query nga.selecteditem, mao cguro ni reason nganong dili ma bind ang data, napa lain na way sa pagcapture sa value sa listbox bro? lamat bro

  6.    Advertisement

Similar Threads

 
  1. Replies: 3
    Last Post: 12-22-2011, 02:52 PM
  2. HELP ! bout listbox s vb.net
    By y0yie_14 in forum Programming
    Replies: 1
    Last Post: 10-12-2010, 03:26 PM
  3. TABANG ! unsaon pglistbox to listbox sa vb.net ?
    By y0yie_14 in forum Programming
    Replies: 0
    Last Post: 10-11-2010, 11:29 AM
  4. share youre vb.net 2005 tutorials..
    By labo13 in forum Programming
    Replies: 2
    Last Post: 07-21-2008, 04:33 PM
  5. Using custom cursors in VB.NET
    By DeathFox in forum Programming
    Replies: 0
    Last Post: 11-25-2007, 09:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top