Ejemplo 1: código de ejemplo de c # de actualización del servidor sql
string name = "test1";
int id = 1;
using (SqlConnection cnn = new SqlConnection("Server=localhost;Database=DEV;User Id=test;[email protected]#$;Connect Timeout=5400"))
{
cnn.Open();
string querystr = "UPDATE [dbo].[TABLE] SET [name][email protected]_name WHERE [id][email protected]_id";
using (var cmd = new SqlCommand(querystr, cnn))
{
//set value
cmd.Parameters.AddWithValue("@p_name", name);
//where with id
cmd.Parameters.AddWithValue("@p_id", id);
int ret = cmd.ExecuteNonQuery();
}
}
Ejemplo 2: como actualizar la base de datos usando sql en 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();
}
}
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)