Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SqlDataReader reader = cmd.ExecuteReader();
                               
                while (reader.Read())
                {
                    string addStr = reader.GetString("emp_firstname");
                    comboBox1.Items.Add(addStr);
                }


What I have tried:

SqlDataReader reader = cmd.ExecuteReader();
                               
                while (reader.Read())
                {
                    string addStr = reader.GetString(emp_firstname);
                    comboBox1.Items.Add(addStr);
                }
Posted
Updated 19-Feb-18 18:25pm
v2

Please, read MSDN documentation. Reader.GetString() method[^] expects integer value as a parameter, but you pass a string.
 
Share this answer
 
SqlDataReader reader = cmd.ExecuteReader();
                               
                while (reader.Read())
                {
                    string addStr = reader.GetString("emp_firstname");
                    comboBox1.Items.Add(addStr);
                }


string addStr = reader.GetString(emp_firstname);
                    comboBox1.Items.Add(addStr);


insted of above code i am wrote below code i got expected result


comboBox1.Items.Add(reader["emp_fristname"].ToString());
 
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