16. SQLite Update, Delete
01.
더보기
1.
Title="ContactDetailsWindow"
Height="300"
Width="260">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="4" />
<RowDefinition Height="auto" />
<RowDefinition Height="4" />
<RowDefinition Height="auto" />
<RowDefinition Height="4" />
<RowDefinition Height="auto" />
<RowDefinition Height="4" />
<RowDefinition Height="auto" />
<RowDefinition Height="4" />
<RowDefinition Height="auto" />
<RowDefinition Height="4" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="4" />
</Grid.ColumnDefinitions>
<TextBox x:Name="nameTextBox"
Grid.Row="1"
Grid.Column="1" />
<TextBox x:Name="emailTextBox"
Grid.Row="3"
Grid.Column="1" />
<TextBox x:Name="PhoneTextBox"
Grid.Row="5"
Grid.Column="1" />
<Button Grid.Row="7"
Grid.Column="1"
Content="Update"
Click="UpdateButton_Click" />
<Button Grid.Row="9"
Grid.Column="1"
Content="Delete"
Background="Red"
Foreground="White"
Click="DeleteButton_Click" />
</Grid>
2.
3.
4.
// EditContactWindow 를 출력하고,
// 생성자로 contactListView 컨트롤에서 선택한 Contact 객체를 전달합니다.
EditContactWindow newContactWindow = new EditContactWindow(selectContact);
newContactWindow.ShowDialog();
5.
// SQLite 데이터베이스 연결 객체에서
using (SQLiteConnection connection = new SQLiteConnection(App.databasePath))
{
connection.CreateTable<Contact>();
// 전달받은 Contact 객체에 해당하는 테이블 값을 삭제합니다.
connection.Delete(contact);
}
Close();
02.
더보기
1.
// SQLite 데이터베이스 연결 객체에서
using (SQLiteConnection connection = new SQLiteConnection(App.databasePath))
{
connection.CreateTable<Contact>();
// 전달받은 Contact 객체에 해당하는 테이블 값을 갱신합니다.
connection.Update(contact);
}
2.
nameTextBox.Text = contact.Name;
emailTextBox.Text = contact.Email;
PhoneTextBox.Text = contact.Phone;
contact.Name = nameTextBox.Text;
contact.Email = emailTextBox.Text;
contact.Phone = PhoneTextBox.Text;
3.
03.