Doe Jowns Doe Jowns - 2 years ago 89
ASP.NET (C#) Question

Why does not this SQL server INSERT query execute?

I work on an ASP.NET project (using and have now a problem with a database query :

public ActionResult SimonTest(int id, int obj)
SqlConnection myConn = new SqlConnection(@"Server=(LocalDb)\MSSqlLocalDB;Integrated security=SSPI;database=Serene5_Default_v1");

// skipped code building the following command :

command = "INSERT INTO [Serene5_Default_v1].[tcpdump].[Errors] (TimeStp,IdSource,IdDestination,PortSource,PortDestination,ToTheRight,ToTheLeft) VALUES ('11:2','11','1','1','1',1,1);";

SqlCommand myCommand2 = new SqlCommand(listDb, myConn);


System.Diagnostics.Debug.WriteLine("Commande exécutée");

return View("~/Modules/Default/TcpDump/TcpDumpIndex.cshtml");

When I execute the query
with Microsoft SQL Server Management Studio, nothing goes wrong, but here the command seems to be skipped (no exception raised and nothing written in database)

Answer Source

You forgot to assign sql text to command myCommand2.CommandText = command before executing query.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download