Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void AutoradioButton1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Server=CHRIS-PC\\SQLEXPRESS;Database=jasmineSql.sdf;" +
"Integrated Security=True");
conn.Open();
DataSet sds = new DataSet();
SqlCommand scmd = new SqlCommand("SELECT Description FROM TblCategories", conn);
SqlDataAdapter sadptr = new SqlDataAdapter(scmd);
sadptr.Fill(sds, "TblCategories");
this.listBox1.DataSource = sds.Tables["TblCategories"];
this.listBox1.DisplayMember = "Description";
listBox1.DataBind();
}


Populating a Listbox from the desired column in a Particular table (I have 3 table in a my database)

Please can you tell me what is going worng. I coudn't see the Values entered in the column "TblCategories" in my listBox1 when I clicked the radio button.

Error - System.Windows.Forms.ListBox does not contain a definition for
DataBind.

still unable to pull describtion in listbox

Note: I am getting ListBox1.Databindings(); Not listBox1.DataBind();
Is this causing to not populate. Please help.

Can anyone provide me with a solution?
Thanks.
Posted
Updated 19-Sep-10 7:37am
v3
Comments
Sandeep Mewara 19-Sep-10 13:18pm    
PRE tags are your friend. Use it to format code part.

Are you using System.Windows.Forms.ListBox.

If you are in Windoows application you do not need to use DataBind. If you set DataSource and DispayMember it would be fine.

What problem do you face if you omit the line ListBox1.DataBind?
 
Share this answer
 
Problem solved. Thank you guys for help me.

Populating listbox with desired SQL colmn:

Correct code:

namespace MovieProject
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void AutoradioButton1_Click(object sender, EventArgs e)
{

SqlConnection conn = new SqlConnection("Server=CHRIS-PC\\SQLEXPRESS;Database=Tblcat;" +
"Integrated Security=True");


SqlCommand scmd = new SqlCommand("SELECT Description FROM Moviecat", conn);

DataSet sds = new DataSet();


conn.Open();

SqlDataAdapter sadptr = new SqlDataAdapter(scmd);
sadptr.Fill(sds, "Moviecat");


if (sds.Tables["Moviecat"].Rows.Count == 0)

{

MessageBox.Show("There are no DB.");

}

else
{

this.listBox1.DataSource = sds.Tables["Moviecat"];
this.listBox1.DisplayMember = "Description";

}

conn.Close();

}


}
}
<pre><pre>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900