public IActionResult Edit(int id) { string connectionString = @"Data Source=DESKTOP-B3VTHPB\SQLEXPRESS;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";//Configuration["ConnectionStrings:DefaultConnection"]; cCuentas clsCuentas = new cCuentas(); using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"Select * From [DB2].[dbo].[Cuentas] Where ID='{id}'"; SqlCommand command = new SqlCommand(sql, connection); connection.Open(); using (SqlDataReader dataReader = command.ExecuteReader()) { while (dataReader.Read()) { clsCuentas.ID = Convert.ToInt32(dataReader["ID"]); clsCuentas.Description = Convert.ToString(dataReader["Description"]); clsCuentas.ID_Origen = Convert.ToInt32(dataReader["ID_Origen"]); } } connection.Close(); } return(View(clsCuentas)); }
public IActionResult Create(cCuentas clsCuentas) { if (ModelState.IsValid) { string connectionString = @"Data Source=DESKTOP-B3VTHPB\SQLEXPRESS;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";//Configuration["ConnectionStrings:DefaultConnection"]; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"Insert Into [DB2].[dbo].[Cuentas](ID, Description,ID_Origen) Values('{clsCuentas.ID}', '{clsCuentas.Description}', '{clsCuentas.ID_Origen}')"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); command.ExecuteNonQuery(); connection.Close(); } return(RedirectToAction("Index")); } } else { return(View()); } }
public IActionResult Edit_Post(cCuentas clsCuentas) { string connectionString = @"Data Source=DESKTOP-B3VTHPB\SQLEXPRESS;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";//Configuration["ConnectionStrings:DefaultConnection"]; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"Update [DB2].[dbo].[Cuentas] SET ID='{clsCuentas.ID}', Description='{clsCuentas.Description}', ID_Origen='{clsCuentas.ID_Origen}'"; using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); command.ExecuteNonQuery(); connection.Close(); } } return(RedirectToAction("Index")); }