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

Excel: Split Word Into Separate Cells In Excel

 See  https://www.extendoffice.com/documents/excel/1697-excel-split-word-into-letters.html In a blank cell next to your data, C1 for instanc...