title: Run SQL Command in Asp Net
body: <p>I want to write a value to a SQLite Database when I click on a button. How can I archive that? I found out how I can read data from a database using models, but not how to write data.</p>
  <pre><code>@model IEnumerable&lt;Sooziales_Netzwerk.Models.Link&gt;
  @using Microsoft.AspNetCore.Identity;
  @inject SignInManager&lt;IdentityUser&gt; SignInManager
  @inject UserManager&lt;IdentityUser&gt; UserManager
  
  @{
  ViewData[&quot;Title&quot;] = &quot;Home Page&quot;;
  String username = User.Identity?.Name;
  if(User.IsInRole(&quot;verified&quot;)){
     username = username + &quot;✓&quot;;
  }
  }
  
  &lt;div class=&quot;text-center&quot;&gt;
  @if(SignInManager.IsSignedIn(User))
  {
      &lt;h1 class=&quot;display-4&quot;&gt;Welcome @username&lt;/h1&gt;
  }else 
  {
      &lt;h1 class=&quot;display-4&quot;&gt;SavedThat&lt;/h1&gt;
      &lt;p&gt;Link your Life up!&lt;/p&gt;
  }
  
  @foreach (var item in Model) {
      &lt;script&gt;
          function copyToClipboard(var linktext){
              window.clipboardData.setData('Text', linktext);
          }
      &lt;/script&gt;
      &lt;h2&gt;@Html.DisplayFor(modelItem =&gt; item.linkText)&lt;/h2&gt;
      &lt;p&gt;@Html.DisplayFor(modelItem =&gt; item.username)&lt;/p&gt;
      
      bool liked = false;
      var selectedQueryString = &quot;UPDATE Link SET likes = 1 WHERE idLink = &quot; + item.idLink;
      &lt;button onclick=&gt; @Html.DisplayFor(modelItem =&gt; item.likes)&lt;/button&gt;
      &lt;button onclick=copyToClipboard(@item.linkText)&gt;Share&lt;/button&gt;
  }
  </code></pre>
  
  <p>This is my index.cshtml. I want to run the SQL Command in the variable selectedQueryString when clicked on the Button .</p>
  <p>This is my HomeController.cs:</p>
  <pre><code>using System.Diagnostics;
  using Microsoft.AspNetCore.Mvc;
  using Sooziales_Netzwerk.Models;
  using Microsoft.EntityFrameworkCore;
  using Sooziales_Netzwerk.Data;
  
  namespace Sooziales_Netzwerk.Controllers;
  
  public class HomeController : Controller
  {
  private readonly ILogger&lt;HomeController&gt; _logger;
  private readonly Sooziales_NetzwerkDbContext _context;
  
  /*public HomeController(ILogger&lt;HomeController&gt; logger)
  {
      _logger = logger;
  }*/
  
  public HomeController(Sooziales_NetzwerkDbContext context, ILogger&lt;HomeController&gt; logger)
  {
      _context = context;
      _logger = logger;
  }
  
  public async Task&lt;IActionResult&gt; Index()
  {
      return View(await _context.Link.ToListAsync());
  }
  
  public IActionResult Privacy()
  {
      return View();
  }
  
  public IActionResult TermsOfService()
  {
      return View();
  }
  
  [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
  public IActionResult Error()
  {
      return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
  }
  }
  </code></pre>