I have read the int "anzahl" with DataReader. Now I want to work with this number. The problem is: I cannot access the int from outside the while loop. The error shows "use of unassigned local variable". How can i make "anzahl" available? Here is my code:
int anzahl;
string uid = uidTextbox.Text;
string query1 = string.Format("SELECT Chip_Anzahl FROM chipTable WHERE Chip_ID = '{0}';",
                              uid);
try
{
    sqlConnection = new SqlConnection(connectionString);
    SqlCommand sqlCmd = new SqlCommand(query1, sqlConnection);
    sqlCmd.CommandText = query1;
    sqlConnection.Open();
    SqlDataReader dataReader = sqlCmd.ExecuteReader();
    while(dataReader.Read())
    {
        anzahl = dataReader.GetInt32(0);
    }
    dataReader.Close();
    sqlConnection.Close();
}
catch (Exception E)
{
    MessageBox.Show(E.ToString());
}
int newnumb = anzahl + 5;
MessageBox.Show(newnumb.toString());
 
    