ADO.Net. Why doesn’t the insert happen?

I looked at MSDN pages to find out ADO.Net using commands. I can read using the sample code posted there.

But when I tried to use the modification code below, the insertion does not occur. I do not understand why. Can someone please tell me what is wrong with this code?

string connectionString = "A_VALID_CONNECTION_STRING";
string commandText = 
"INSERT INTO Contacts (FullName, Mobile) VALUES ('Pierce Brosnan', '1800-007')";

SqlConnection connection = new SqlConnection(connectionString);          

try
{
  connection.Open();
  SqlCommand command = new SqlCommand(commandText, connection);
  Console.WriteLine(command.ExecuteNonQuery());
  connection.Close();
}
catch (Exception ex)
{
  Console.WriteLine(ex.Message);
}

Edit

  • No exception is thrown.

  • ExecuteNonQuery (), which should return no. returned rows returns 1.

  • Environment: Visual C # 2010 Express | SQL Server 2008 Express | Windows 7 Ultimate 32-bit.

Update

  • MDF, . , , SQL- . . .

  • SQL Server 2008 Express, Visual # 2010 Express. MDF .

  • SQL Server 2008 Express Management Studio Express.

  • .

  • .

INSERT !

P.S. , , . .

+3
1

, :

  • Database.mdf
  • : Server=.\SQLExpress;AttachDbFilename=database.mdf;Database=dbname; Trusted_Connection=Yes;, .. .

, / , , Database.mdf ApplicationProjectFolder\bin\Debug, , , Database.mdf . , , , "" Database.mdf ApplicationProjectFolder\database.mdf ApplicationProjectFolder\bin\Debug\database.mdf, , "". , Database.mdf, , " " .

, "INSERT" , "reset" , .

+3

Source: https://habr.com/ru/post/1764284/


All Articles