让connectionstrin为:
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);
v通过调用SubmitChanges()
我们类的对象的更新数据实际上正在写入实际的数据库中