Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
when i am run my program. only first employee details is i got it. i am select second employee not retrive the second employee. only first employee details is retrive it.

how i am got selected employee details in my web form.

C#
protected void Page_Load(object sender, EventArgs e)
    {
        string connection = System.Configuration.ConfigurationManager.ConnectionStrings["aaa2"].ConnectionString;
        SqlConnection con = new SqlConnection(connection);
        con.Open();
        SqlCommand cmd = new SqlCommand("Select td_em_id from pa_tds_int_entry", con);
        SqlDataReader dr = cmd.ExecuteReader();
        ddlId.DataSource = dr;
        ddlId.DataTextField = "td_em_id";
        ddlId.DataBind();
        
    }
Posted
Updated 7-Feb-12 20:19pm
v2
Comments
NikulDarji 8-Feb-12 2:22am    
Use WHERE condition....Select employee by some unique field e.g. td_em_id :)

Refer This Link

http://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.71).aspx[^]

Accept This Answer If It Has Helped You.
 
Share this answer
 
Hi,

You can do this based on your sample

SQL
string connection = System.Configuration.ConfigurationManager.ConnectionStrings["aaa2"].ConnectionString;
SqlConnection con = new SqlConnection(connection);
con.Open();
SqlCommand cmd = new SqlCommand("Select td_em_id from pa_tds_int_entry WHERE td_em_id = '" + ddlId.SelectedValue + "' ", con);
SqlDataReader dr = cmd.ExecuteReader();
ddlId.DataSource = dr;
ddlId.DataTextField = "td_em_id";
ddlId.DataBind();

I hope this one can help.
 
Share this answer
 
v2
Comments
2011999 8-Feb-12 2:36am    
Error converting data type varchar to numeric.

i got this error
Anuja Pawar Indore 8-Feb-12 2:57am    
Added pre tag
use while loop for DataReader object,
eg.
C#
while(dr.Read())
{
foreach(int k in dr)
   {
          Console.WriteLine(dr[k]);
   }
}




you will get your output...good luck..
 
Share this answer
 

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