Thursday, April 9, 2020

Insert a new record into the SQL table using Insert Into

This example inserts an integer (PersonID, a varchar (LastName), and float (LargeNumber) variable.

Note that for the SQL, it is a float which is 8 bytes, which corresponds to a double in .Net, see https://stackoverflow.com/questions/1056323/difference-between-numeric-float-and-decimal-in-sql-server




SqlCommand command = new SqlCommand("INSERT INTO dbo.FRANK (PersonID,LastName,LargeNumber) VALUES (@id,@lastname,@number)",cnn);
double BigNumber = 1234.564;
command.Parameters.AddWithValue("@id", 1);
command.Parameters.AddWithValue("@lastname", "John Hufnagel");
command.Parameters.AddWithValue("@number", BigNumber);
int result = command.ExecuteNonQuery();
Console.WriteLine("I think it is done");
// Check Error
if (result < 0)
  Console.WriteLine("Error inserting data into Database!");
                

No comments:

Post a Comment

Cocktail Jazz for Beginners

  https://pianowithjonny.com/piano-lessons/how-to-play-beginner-cocktail-piano-in-3-steps/ https://www.pianogroove.com/jazz-piano-lessons/co...