Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
private void populatesocietyname()
{
string CS = ConfigurationManager.ConnectionStrings["SocietyCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("Select SocietyID,SocietyFullName from tblsociety", con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
ddlsocietyname.DataTextField = "SocietyFullName";
ddlsocietyname.DataValueField = "SocietyID";
ddlsocietyname.DataSource = grdr;
ddlsocietyname.DataBind();
ddlsocietyname.Items.Insert(0, n
ew ListItem("-- Select Society Name --", "0"));
}
}

This code in win form give error i tried to change the datatext to valuedisplay a datavaluefield to valuedisplay but it give error at datasource how i can solve this?
Posted

1 solution

try below
C#
ddlsocietyname.DisplayMember = "SocietyFullName";
ddlsocietyname.ValueMember = "SocietyID";
ddlsocietyname.DataSource = grdr;
//ddlsocietyname.DataBind();
 
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