.Net Framework error :SqlClient.SqlException: 'Invalid object name 'dbo.GestAttivita'.'

-1

Im trying to make CRUD aplication in .net Framework, where I can insert/edit/delete employee in SQL Server. When i try to insert new employee it gaves me error : "System.Data.SqlClient.SqlException: 'Invalid object name 'dbo.GestAttivita'.' " in controller.

This is my controller :

using static DataLibrary.Logic.ProcessoreTecnico;           
            [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult SignUp(TecniciModel tecniciModel)
            {
                if (ModelState.IsValid)
                {
                    int recordsCreated = CreareTecnico(tecniciModel.Id,
                        tecniciModel.Nome,
                        tecniciModel.Cognome,
                        tecniciModel.Cellulare);
                    return RedirectToAction("Index");
                }

                return View();
            }

Here is the error

SqlException (0x80131904): Invalid object name 'GestAttivita'

DB Structure

And this is the class ProcessoreTecnico :

public static class ProcessoreTecnico
    {
        public static int CreareTecnico(int id, string nome, string cognome, 
             string cellulare)
        {
            TecniciModel data = new TecniciModel
            {
                Id = id,
                Nome = nome,
                Cognome = cognome,
                Cellulare = cellulare
            };

            string sql = @"insert into dbo.GestAttivita(id, nome, cognome,  cellulare)
                            values (@Id, @Nome, @Cognome, @Cellulare);";

            return SqlDataAccess.SaveData(sql, data);
        }

        public static List<TecniciModel> CaricaTecnici()
        {
            string sql = @"select id, nome, cognome, cellulare
                            from dbo.GestAttivita;";

            return SqlDataAccess.LoadData<TecniciModel>(sql);
        }
    }

I can't get it gives me that error. Any ideas how to fix this? Thanks in advance!

c#
.net
sql-server
.net-framework-version
asked on Stack Overflow Jun 15, 2020 by ewardz1 • edited Jun 15, 2020 by ewardz1

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0