-3

Right now, I can write records one by another, as it's shown below. How do I rewrite a single record each time? For example only first one.

enter image description here

Code Behind:

 public static List<PersonModel> LoadPeople()
    {
        using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
        {                
            var output = cnn.Query<PersonModel>("select * from Person", new DynamicParameters());
            return output.ToList();
        }
    }

    public static void SavePerson(PersonModel person)
    {
        using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
        {
            cnn.Execute("insert into Person (FirstName, LastName) values (@FirstName, @LastName)", person);

        }
    }

    private static string LoadConnectionString(string id = "Default")
    {
        return ConfigurationManager.ConnectionStrings[id].ConnectionString;
    }
Msorich
  • 113
  • 1
  • 10

1 Answers1

1

If you want to update the first row (id=1), you can go to the Execute SQL tab and use this:

UPDATE Person SET FirstName=Mitsubishi WHERE Id=1;

In your c# code I guess it would be:

public static void UdatePerson(PersonModel person, int id)
    {
        using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
        {
            cnn.Execute("update Person (FirstName, LastName) set (@FirstName, @LastName) where Id = @id", new {person, id});
        }
    }

Take a look at that link if you need further information: https://dapper-tutorial.net/execute

vvilin
  • 185
  • 10