num = textBox5.Text; using (OleDbConnection oledb = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\WhiteChemist-PC\source\repos\ГСМ\ГСМ\GSM.accdb")) { oledb.Open(); OleDbCommand command = new OleDbCommand(string.Format($"SELECT (Normaras) FROM [Table] WHERE [Numb] = '{0}'", num), oledb); using (OleDbDataReader dataReader = command.ExecuteReader()) { norma = command.ExecuteScalar().ToString(); if (radioButton1.Checked == true && comboBox2.SelectedIndex == 0) { try { k = int.Parse(norma); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } nadb = (k* (5 / 100)); command = new OleDbCommand(string.Format($"INSERT INTO [Table].[(Nad)] VALUES ('{0}')", nadb.ToString()), oledb); while (dataReader.Read() == true) command.ExecuteNonQuery(); } In the line norma=command.ExecuteScalar().ToString() throws an exception:
System.InvalidOperationException: "There is an open DataReader assigned to this command by Command that needs to be closed in advance."
Prior to this, there have never been such errors when working with DB. Who knows what's the matter?
ExecuteScalarandExecuteReader. Leave one thing. - Alexander Petrovusingfor allDisposableobjects (including command). - Alexander Petrov