SQL request for C# not received



  • I write to SQL the following request:

    SELECT *
    FROM Materials,
         PARAMETERS,
         [Values],
         Suppliers,
         Sensors
    WHERE [Values].MaterialId = Materials.Id
      AND [Values].SensorId = Sensors.Id
      AND Materials.SupplierId = Suppliers.Id
      AND PARAMETERS.Id = Sensors.ParameterId
      AND MaterialName='Зерно'
    

    Everything works correctly, That's what I'm trying to write on C#:

    _comandText = "SELECT * FROM Materials,Parameters,[Values],Suppliers,Sensors WHERE [Values].MaterialId = Materials.Id AND [Values].SensorId = Sensors.Id AND Materials.SupplierId = Suppliers.Id AND Parameters.Id = Sensors.ParameterId";
    ...
    _comandText += " AND MaterialName='" + m.MaterialName + "'";
    // _comandText на 100% совпадает с запросом на SQL, я брал его(запрос для SQL) прямо отсюда во время дебага проги
    ...
    private DataTable _table;
    ...
    _table = RaportGateway.Instance.GetRaport(_comandText);
    ...
     public DataTable GetRaport(string commandText)
            {
                cmd = new SqlCommand(commandText, Connection);
                _adapter = new SqlDataAdapter(cmd);
                try
                {
                    _adapter.Fill(_table);
    
                return _table;
            }
            catch (Exception ex)
            { // тут ловится Value cannot be null.Parameter name: dataTable, в _table соответственно null
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (Connection.State == ConnectionState.Open)
                    Connection.Close();
            }
        }
    

    Why would that be?



  • private DataTable _table = new DataTable();
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2