0

I got error in "sqlDR.GetString("SECTION_NAME")".

SqlConnection conn = new SqlConnection(StringConnection.sqlAddress);
            SqlCommand comm = new SqlCommand("select SECTION_NAME from SECTION", conn);
            SqlDataReader sqlDR;

            try
            {
                conn.Open();
                sqlDR = comm.ExecuteReader();

                while (sqlDR.Read())
                {
                    string branch = sqlDR.GetString("SECTION_NAME");
                    cmbBranch.Items.Add(branch);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
AJ Moquete
  • 29
  • 6

2 Answers2

0

You cant use GetSrting() with a string parameter. GetString() gets the column index as a parameter. In your example SECTION_NAME has 0 column index. So your code must be sqlDR.GetString(0);

if your query was select SOMETHING_ELSE,SECTION_NAME from SECTION" your code must be sqlDR.GetString(1); to get the value of SECTION_NAME

SpyrosLina
  • 131
  • 7
0

sqlDR.GetString("SECTION_NAME") method requires integer as parameter

your parameter is string with the value of "SECTION_NAME".