接続文字列を次のようにします。
string pp = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\AdventureWorks2012_Data.mdf;Integrated Security=True;Connect Timeout=30";
および更新タスクは以下のとおりです。
public async Task callupdate()
{
try
{
int ppp = Convert.ToInt32(textBox1ID.Text);
DataClasses1DataContext dc = new DataClasses1DataContext(pp);
Person person = dc.Persons.Single(c => c.BusinessEntityID == ppp);
person.PersonType = Convert.ToString(PersonTypecomboBox1.SelectedItem);
person.PersonType = Convert.ToString(PersonTypecomboBox1.SelectedItem);
if (NameStylecomboBox1.SelectedText == "False")
person.NameStyle = false;
else
person.NameStyle = true;
person.Title = Convert.ToString(TitlecomboBox1.SelectedItem);
person.FirstName = FirstNametextBox2.Text;
person.MiddleName = MiddleNametextBox3.Text;
person.LastName = LastNametextBox4.Text;
person.Suffix = SuffixtextBox5.Text;
person.EmailPromotion = Convert.ToInt32(EmailPromotiontextBox6.Text);
person.ModifiedDate = DateTime.Today;
dc.SubmitChanges();
}
catch(Exception exp)
{
}
}
それ以外の DataClasses1DataContext dc = new DataClasses1DataContext();
DataClasses1DataContext dc = new DataClasses1DataContext(pp);
私たちのクラスのオブジェクトである更新データを呼び出すSubmitChanges()
ことによって、実際のデータベースに実際に書き込まれています