0

I want to get the values of the column "nome" from the database to insert into a comboBox, this error appears, how can I solve it?

SqlConnection conn = new SqlConnection(@"Data Source=DESKTOP-J28HRE9;Initial Catalog=bd_sbs;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select * from dbo.fornecedores", conn);
SqlDataReader myReader;              
conn.Open();
myReader = cmd.ExecuteReader();

while (myReader.Read())
{
    string sNome = myReader.GetString("nome");
    comboBox1.Items.Add(sNome);
}

the error appears on the line string sNome = myReader.GetString("nome");

Mohammad Aghazadeh
  • 2,108
  • 3
  • 9
  • 20

0 Answers0