Answers for "how to update database using sql in c#"

C#
0

how to update database using sql in c#

using (var sqlConnection = new SqlConnection(config.ConnectionString))
{
	foreach(var position in positions)
	{
		var sql =
         	$"UPDATE BillOfMaterial SET Position = '{pos}' WHERE Creator = '{position.Creator}' AND Idx = '{position.Idx}' AND ArtNumber = '{position.ArtNumber}'";
          using (var sqlCommand = new SqlCommand(sql,sqlConnection))
          {
               sqlConnection.Open();
               sqlCommand.ExecuteNonQuery();
               sqlConnection.Close();
          }
   	}
}
Posted by: Guest on April-08-2021
0

Update data in db .net

// Query the database for the row to be updated.
var query =
    from ord in db.Orders
    where ord.OrderID == 11000
    select ord;

// Execute the query, and change the column values
// you want to change.
foreach (Order ord in query)
{
    ord.ShipName = "Mariner";
    ord.ShipVia = 2;
    // Insert any additional changes to column values.
}

// Submit the changes to the database.
try
{
    db.SubmitChanges();
}
catch (Exception e)
{
    Console.WriteLine(e);
    // Provide for exceptions.
}
Posted by: Guest on April-16-2020

Code answers related to "how to update database using sql in c#"

C# Answers by Framework

Browse Popular Code Answers by Language