Friday, 27 September 2013

combobox insert text and value gives error

combobox insert text and value gives error

I want to insert each row in SQL into combobox, where EmployeeID will be
combobox Value, and EmployeeFirstName EmployeeLastName will be text of
combobox item. However this line



comboBox1.Items.Insert(dr.GetString(1) + dr.GetString(2), dr.GetInt32(0));



gives me this error:
Error 1 The best overloaded method match for
'System.Windows.Forms.ComboBox.ObjectCollection.Insert(int, object)' has
some invalid arguments
C:\Users\bilgisayar\Desktop\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs
45 21 WindowsFormsApplication1



void comboboxrefresh()
{
cnn.Open();
SqlCommand cmd = new SqlCommand("SELECT
EmployeeID,EmployeeFirstName,EmployeeLastName FROM Employees",
cnn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
comboBox1.Items.Insert(dr.GetString(1) + dr.GetString(2),
dr.GetInt32(0));
}
}
cnn.Close();
}

No comments:

Post a Comment