本文介绍了使用MS Access和C#Winforms加速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想知道是否有人可以帮助我完成我正在做的项目。我现在接近完成,但程序真的很迟钝。这是由于MS Access和C#程序之间不断更新/归档。因为多个用户将更新数据,我需要不断更新程序上的数据。我的问题是,速度有什么解决方案吗? 我在下面列出了我的一个.cs文件,以显示我是如何做到的。 使用System; 使用System.Collections.Generic;使用System.ComponentModel ; 使用System.Data; 使用System.Diagnostics;使用System.Drawing ; 使用System.Globalization; 使用System.Linq; 使用System.Text; 使用System.Windows.Forms;使用DevComponents.DotNetBar ; 使用MAB.PCAPredictCapturePlus; namespace HRSystem { public partial class Course_Attendee:DevComponents.DotNetBar.Metro.MetroForm { public int CurrentPosition = 0; public BindingSource formDataSource; public HR_Dataset.RoleDataTable RoleListTable; public HR_Dataset.Course_Attendee_BioRow LinkedBio; public int AttendeeID = 0; public int LastAttendeeID = 0; public bool NewRecord = false; public Course_Attendee(BindingSource dataSource) { formDataSource = dataSource; InitializeComponent(); RoleListTable = new HR_Dataset.RoleDataTable(); this.peopleTableAdapter.Fill(this.hR_Dataset.People); this.course_Attendee_StatusTableAdapter.Fill(hR_Dataset.Course_Attendee_Status); this.course_Attendee_BioTableAdapter1.Fill(hR_Dataset.Course_Attendee_Bio); this.course_AttendeeTableAdapter.Fill(hR_Dataset.Course_Attendee); date_booking.DataBindings.Add(" ValueObject",formDataSource," Booking Date"); combo_status.DataBindings.Add(" SelectedValue",formDataSource," Status",true); txt_invname.DataBindings.Add(" Text",formDataSource," Invoice Name",true); txt_invaddr.DataBindings.Add(" Text",formDataSource," Invoice Address",true); textbox_ponumber.DataBindings.Add(" Text",formDataSource," PO Number",true); combo_assosrole.DataBindings.Add(" SelectedValue",formDataSource," Associated Role"); txt_ID.DataBindings.Add(" Text",formDataSource," ID"); txt_extorg.DataBindings.Add(" Text",formDataSource," Organization"); txt_extrole.DataBindings.Add(" Text",formDataSource," Role"); combo_extrolecat.DataBindings.Add(" SelectedValue",formDataSource," Role Category",true); txt_extmanagername.DataBindings.Add(" Text",formDataSource," Managers Name"); txt_managerno.DataBindings.Add(" Text",formDataSource," Managers Number"); txt_manageremail.DataBindings.Add(" Text",formDataSource," Managers Email"); txt_cost.DataBindings.Add(" ValueObject",formDataSource," Cost"); check_paid.DataBindings.Add(" Checked",formDataSource," Paid"); CAttendee_navigator.BindingSource = formDataSource; formDataSource.PositionChanged + = FormDataSource_PositionChanged; } private void FormDataSource_PositionChanged(object sender,EventArgs e) { CurrentPosition = formDataSource.Position; } private void course_AttendeeBindingNavigatorSaveItem_Click(object sender,EventArgs e) { this.Validate(); this.formDataSource.EndEdit(); course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); } private void SetExternalFields(bool Visible) { layout_extorg.Visible = Visible; layout_extrole.Visible =可见; layout_extrolecat.Visible =可见; layoutSpacerItem4.Visible =可见; layout_extmanagername.Visible =可见; layout_extmanagerno.Visible =可见; layout_extmanageremail.Visible =可见; } private void combo_assosrole_TextUpdate(object sender,EventArgs e) { if(formDataSource.Current!= null) { AttendeeID =(int )((DataRowView的)this.formDataSource.Current).Row [" ID"]; LinkedBio =(来自h in hR_Dataset.Course_Attendee_Bio,其中h.ID == AttendeeID select h).FirstOrDefault(); if(!LinkedBio.IsInternalPersonNull()) { RefreshRoleList(LinkedBio.InternalPerson.ToString()); if(combo_assosrole.Items.Count> 0) layout_assosrole.Visible = true; else layout_assosrole.Visible = false; SetExternalFields(false); } 其他 { layout_assosrole.Visible = false; SetExternalFields(true); } } } private void txt_attendee_TextChanged(object sender,EventArgs e) { if(formDataSource.Current!= null) ) { DataTable Test = formDataSource.Table(); AttendeeID =(int)((DataRowView)this.formDataSource.Current).Row [" Attendee_Record"]; LinkedBio =(来自h in hR_Dataset.Course_Attendee_Bio,其中h.ID == AttendeeID select h).FirstOrDefault(); if(LinkedBio!= null) { if(!LinkedBio.IsInternalPersonNull()) { RefreshRoleList(LinkedBio.InternalPerson.ToString()); if(combo_assosrole.Items.Count> 0) layout_assosrole.Visible = true; else layout_assosrole.Visible = false; SetExternalFields(false); } 其他 { layout_assosrole.Visible = false; SetExternalFields(true); } } } } private void txt_attendee_ButtonCustomClick(object sender,EventArgs e) { AttendeeInfo Info =新的AttendeeInfo(LinkedBio); Info.ShowDialog(); txt_attendee.Text = Info.LinkedBio.FullName; course_AttendeeTableAdapter.Update(hR_Dataset.Course_Attendee); course_Attendee_BioTableAdapter1.Update(Info.LinkedBio); } private void p_savenclose_Click(object sender,EventArgs e) { this.Validate(); this.formDataSource.EndEdit(); course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); this.Close(); } private void RefreshRoleList(string PersonID) { RoleListTable = roleTableAdapter.GetData_PersonID(int.Parse(PersonID)); combo_assosrole.DataSource = RoleListTable; combo_assosrole.DisplayMember =" Role Title" ;; combo_assosrole.ValueMember =" ID" ;; combo_assosrole.DataBindings.RemoveAt(0); combo_assosrole.DataBindings.Add(" SelectedValue",formDataSource," Associated Role"); } private void Course_Attendee_Load(object sender,EventArgs e) { AttendeeID =(int)((DataRowView)this.formDataSource.Current).Row [" Attendee_Record" ]。 LinkedBio =(来自h in hR_Dataset.Course_Attendee_Bio,其中h.ID == AttendeeID select h).FirstOrDefault(); if(LinkedBio!= null) { if(!LinkedBio.IsInternalPersonNull()) { RefreshRoleList(LinkedBio.InternalPerson.ToString()); if(combo_assosrole.Items.Count> 0) layout_assosrole.Visible = true; else layout_assosrole.Visible = false; SetExternalFields(false); } 其他 { layout_assosrole.Visible = false; SetExternalFields(true); } txt_attendee.Text = LinkedBio.FullName; } } private void LoadData() { course_Attendee_BioTableAdapter1.Fill(hR_Dataset.Course_Attendee_Bio); course_AttendeeTableAdapter.Fill(hR_Dataset.Course_Attendee); } private void txt_ID_TextChanged(object sender,EventArgs e) { bool NewBio = false; if(formDataSource.Current!= null) { if(((DataRowView)this.formDataSource.Current).Row [" Attendee_Record"] == DBNull.Value) { AttendeeSearch Searching = new AttendeeSearch(); Searching.ShowDialog(); if(Searching.CourseAttendee.ID!= 0) {((DataRowView)this.formDataSource.Current).Row [" Attendee_Record"] = Searching.CourseAttendee.ID; course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); int pos = formDataSource.Position; course_AttendeeTableAdapter.Fill(hR_Dataset.Course_Attendee); course_Attendee_BioTableAdapter1.Fill(hR_Dataset.Course_Attendee_Bio); } else { MessageBox.Show("您没有选择或添加与会者,现在将删除当前记录","错误") ,MessageBoxButtons.OK,MessageBoxIcon.Error); formDataSource.RemoveCurrent(); } NewBio = true; } AttendeeID =(int)((DataRowView)this.formDataSource.Current).Row [" Attendee_Record"]; LinkedBio =(来自h in hR_Dataset.Course_Attendee_Bio,其中h.ID == AttendeeID select h).FirstOrDefault(); if(NewBio) { AttendeeInfo Info = new AttendeeInfo(LinkedBio); Info.ShowDialog(); txt_attendee.Text = Info.LinkedBio.FullName; NewBio = false; LinkedBio =(来自h in hR_Dataset.Course_Attendee_Bio,其中h.ID == AttendeeID select h).FirstOrDefault(); } if(LinkedBio!= null) { if(!LinkedBio.IsInternalPersonNull()) { RefreshRoleList(LinkedBio .InternalPerson.ToString()); if(combo_assosrole.Items.Count> 0) layout_assosrole.Visible = true; else layout_assosrole.Visible = false; SetExternalFields(false); } 其他 { layout_assosrole.Visible = false; SetExternalFields(true); } txt_attendee.Text = LinkedBio.FullName; } } } private void bindingNavigator_Movement(object sender,MouseEventArgs e) { try { ToolStripButton nav =(ToolStripButton)sender; formDataSource.EndEdit(); DataTable CAttendeeTable = formDataSource.Table(); HR_Dataset.Course_AttendeeRow NextRole = hR_Dataset.Course_Attendee [formDataSource.Position]; TextInfo textInfo = new CultureInfo(" en-GB",false).TextInfo; switch(nav.Text) { case" Move next": NextRole = hR_Dataset.Course_Attendee [formDataSource.Position + 1]; 休息; case" Move previous": NextRole = hR_Dataset.Course_Attendee [formDataSource.Position - 1]; 休息; case" Move last": NextRole = hR_Dataset.Course_Attendee.LastOrDefault(); 休息; case" Move first": NextRole = hR_Dataset.Course_Attendee.FirstOrDefault(); 休息; } if(NextRole.Lockedby =="") { if(Function.GetChangedColumns(hR_Dataset.Role,StringComparison.InvariantCultureIgnoreCase,true).Count> 0) { DialogResult R = MessageBox.Show("你想保存更改吗?","正在保存",MessageBoxButtons.YesNo,MessageBoxIcon.Information); if(R == DialogResult.Yes) { course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); switch(nav.Text) { case" Move next": formDataSource.MoveNext(); 休息; case" Move previous": formDataSource.MovePrevious(); 休息; case" Move last": formDataSource.MoveLast(); 休息; case" Move first": formDataSource.MoveFirst(); 休息; } } else if(R == DialogResult.No) { if(NewRecord) { formDataSource.RemoveCurrent( ); course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); switch(nav.Text) { case" Move next": formDataSource.MoveNext(); 休息; case" Move previous": formDataSource.MovePrevious(); 休息; case" Move last": formDataSource.MoveLast(); 休息; case" Move first": formDataSource.MoveFirst(); 休息; } } 其他 { hR_Dataset.Role.RejectChanges(); course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); switch(nav.Text) { case" Move next": formDataSource.MoveNext(); 休息; case" Move previous": formDataSource.MovePrevious(); 休息; case" Move last": formDataSource.MoveLast(); 休息; case" Move first": formDataSource.MoveFirst(); 休息; } } } 否则if(R == DialogResult.Cancel) { return; } } else { if(NewRecord) { DialogResult R = MessageBox.Show(" Do you want to保存更改?"," Saving",MessageBoxButtons.YesNo,MessageBoxIcon.Information); if(R == DialogResult.Yes) { course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); } else if(R == DialogResult.No) { formDataSource.RemoveCurrent(); course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); switch(nav.Text) { case" Move next": formDataSource.MoveNext(); 休息; case" Move previous": formDataSource.MovePrevious(); 休息; case" Move last": formDataSource.MoveLast(); 休息; case" Move first": formDataSource.MoveFirst(); 休息; } } } } } 其他 { string [] Name = NextRole.Lockedby.Split( ) ''; MessageBox.Show(" Record当前被'+ textInfo.ToTitleCase(Name [0])+"" + textInfo.ToTitleCase(Name [1]),"Record is locked"锁定, MessageBoxButtons.OK,MessageBoxIcon.Warning); } AttendeeID = int.Parse(txt_ID.Text); } catch(Exception ex) { MessageBox.Show(ex.Message," Error",MessageBoxButtons.OK,MessageBoxIcon.Error); } } private void Course_Attendee_FormClosing(object sender,FormClosingEventArgs e) { formDataSource.EndEdit(); AttendeeID = int.Parse(txt_ID.Text); 开关(e.CloseReason) { case CloseReason.FormOwnerClosing: case CloseReason.TaskManagerClosing: case CloseReason.UserClosing: if(Function.GetChangedColumns(formDataSource.Table(),StringComparison.InvariantCultureIgnoreCase,true).Count> 0) { DialogResult R = MessageBox.Show(""是否要保存更改?" ;,"Save",MessageBoxButtons.YesNo,MessageBoxIcon.Information); if(R == DialogResult.Yes) { course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); } else if(R == DialogResult.No) { if(NewRecord) { formDataSource.RemoveCurrent(); course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); } 其他 { hR_Dataset.Course_Attendee.RejectChanges(); } } else if(R == DialogResult.Cancel) { e.Cancel = true; } } else { if(NewRecord) { DialogResult R = MessageBox.Show(" Do you want to保存更改?"," Saving",MessageBoxButtons.YesNo,MessageBoxIcon.Information); if(R == DialogResult.Yes) { course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); } else if(R == DialogResult.No) { formDataSource.RemoveCurrent(); course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); } else if(R == DialogResult.Cancel) { e.Cancel = true; } } } 休息; case CloseReason.MdiFormClosing: case CloseReason.None: case CloseReason.ApplicationExitCall: case CloseReason.WindowsShutDown: course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource 。表()); 休息; } } } } 解决方案 您好, 您的代码是按照屏幕上的每次更改要求的方式编写的来自服务器的更新。 如果您想减少请求数量 - 请求管理。例如 - 在更改开始/重新启动计时器和du更新他的刻度。 您还可以执行某种本地缓存并在需要时与服务器同步缓存同步。 Hi, I was wondering if someone could help me with a project I am doing. I am now close to completion however the program is just really sluggish. This is due to the constant updating/filing between MS Access and the C# program. Because multiple users will be updating the data I need to constantly update the data on the program. My question is, is there any solution to the speed?I have included one of my .cs files below to show how I am doing this.using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Diagnostics;using System.Drawing;using System.Globalization;using System.Linq;using System.Text;using System.Windows.Forms;using DevComponents.DotNetBar;using MAB.PCAPredictCapturePlus;namespace HRSystem{ public partial class Course_Attendee : DevComponents.DotNetBar.Metro.MetroForm { public int CurrentPosition = 0; public BindingSource formDataSource; public HR_Dataset.RoleDataTable RoleListTable; public HR_Dataset.Course_Attendee_BioRow LinkedBio; public int AttendeeID = 0; public int LastAttendeeID = 0; public bool NewRecord = false; public Course_Attendee(BindingSource dataSource) { formDataSource = dataSource; InitializeComponent(); RoleListTable = new HR_Dataset.RoleDataTable(); this.peopleTableAdapter.Fill(this.hR_Dataset.People); this.course_Attendee_StatusTableAdapter.Fill(hR_Dataset.Course_Attendee_Status); this.course_Attendee_BioTableAdapter1.Fill(hR_Dataset.Course_Attendee_Bio); this.course_AttendeeTableAdapter.Fill(hR_Dataset.Course_Attendee); date_booking.DataBindings.Add("ValueObject", formDataSource, "Booking Date"); combo_status.DataBindings.Add("SelectedValue", formDataSource, "Status", true); txt_invname.DataBindings.Add("Text", formDataSource, "Invoice Name", true); txt_invaddr.DataBindings.Add("Text", formDataSource, "Invoice Address", true); textbox_ponumber.DataBindings.Add("Text", formDataSource, "PO Number", true); combo_assosrole.DataBindings.Add("SelectedValue", formDataSource, "Associated Role"); txt_ID.DataBindings.Add("Text", formDataSource, "ID"); txt_extorg.DataBindings.Add("Text", formDataSource, "Organisation"); txt_extrole.DataBindings.Add("Text", formDataSource, "Role"); combo_extrolecat.DataBindings.Add("SelectedValue", formDataSource, "Role Category", true); txt_extmanagername.DataBindings.Add("Text", formDataSource, "Managers Name"); txt_managerno.DataBindings.Add("Text", formDataSource, "Managers Number"); txt_manageremail.DataBindings.Add("Text", formDataSource, "Managers Email"); txt_cost.DataBindings.Add("ValueObject", formDataSource, "Cost"); check_paid.DataBindings.Add("Checked", formDataSource, "Paid"); CAttendee_navigator.BindingSource = formDataSource; formDataSource.PositionChanged += FormDataSource_PositionChanged; } private void FormDataSource_PositionChanged(object sender, EventArgs e) { CurrentPosition = formDataSource.Position; } private void course_AttendeeBindingNavigatorSaveItem_Click(object sender, EventArgs e) { this.Validate(); this.formDataSource.EndEdit(); course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); } private void SetExternalFields(bool Visible) { layout_extorg.Visible = Visible; layout_extrole.Visible = Visible; layout_extrolecat.Visible = Visible; layoutSpacerItem4.Visible = Visible; layout_extmanagername.Visible = Visible; layout_extmanagerno.Visible = Visible; layout_extmanageremail.Visible = Visible; } private void combo_assosrole_TextUpdate(object sender, EventArgs e) { if (formDataSource.Current != null) { AttendeeID = (int)((DataRowView)this.formDataSource.Current).Row["ID"]; LinkedBio = (from h in hR_Dataset.Course_Attendee_Bio where h.ID == AttendeeID select h).FirstOrDefault(); if (!LinkedBio.IsInternalPersonNull()) { RefreshRoleList(LinkedBio.InternalPerson.ToString()); if (combo_assosrole.Items.Count > 0) layout_assosrole.Visible = true; else layout_assosrole.Visible = false; SetExternalFields(false); } else { layout_assosrole.Visible = false; SetExternalFields(true); } } } private void txt_attendee_TextChanged(object sender, EventArgs e) { if (formDataSource.Current != null) { DataTable Test = formDataSource.Table(); AttendeeID = (int)((DataRowView)this.formDataSource.Current).Row["Attendee_Record"]; LinkedBio = (from h in hR_Dataset.Course_Attendee_Bio where h.ID == AttendeeID select h).FirstOrDefault(); if (LinkedBio != null) { if (!LinkedBio.IsInternalPersonNull()) { RefreshRoleList(LinkedBio.InternalPerson.ToString()); if (combo_assosrole.Items.Count > 0) layout_assosrole.Visible = true; else layout_assosrole.Visible = false; SetExternalFields(false); } else { layout_assosrole.Visible = false; SetExternalFields(true); } } } } private void txt_attendee_ButtonCustomClick(object sender, EventArgs e) { AttendeeInfo Info = new AttendeeInfo(LinkedBio); Info.ShowDialog(); txt_attendee.Text = Info.LinkedBio.FullName; course_AttendeeTableAdapter.Update(hR_Dataset.Course_Attendee); course_Attendee_BioTableAdapter1.Update(Info.LinkedBio); } private void p_savenclose_Click(object sender, EventArgs e) { this.Validate(); this.formDataSource.EndEdit(); course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); this.Close(); } private void RefreshRoleList(string PersonID) { RoleListTable = roleTableAdapter.GetData_PersonID(int.Parse(PersonID)); combo_assosrole.DataSource = RoleListTable; combo_assosrole.DisplayMember = "Role Title"; combo_assosrole.ValueMember = "ID"; combo_assosrole.DataBindings.RemoveAt(0); combo_assosrole.DataBindings.Add("SelectedValue", formDataSource, "Associated Role"); } private void Course_Attendee_Load(object sender, EventArgs e) { AttendeeID = (int)((DataRowView)this.formDataSource.Current).Row["Attendee_Record"]; LinkedBio = (from h in hR_Dataset.Course_Attendee_Bio where h.ID == AttendeeID select h).FirstOrDefault(); if (LinkedBio != null) { if (!LinkedBio.IsInternalPersonNull()) { RefreshRoleList(LinkedBio.InternalPerson.ToString()); if (combo_assosrole.Items.Count > 0) layout_assosrole.Visible = true; else layout_assosrole.Visible = false; SetExternalFields(false); } else { layout_assosrole.Visible = false; SetExternalFields(true); } txt_attendee.Text = LinkedBio.FullName; } } private void LoadData() { course_Attendee_BioTableAdapter1.Fill(hR_Dataset.Course_Attendee_Bio); course_AttendeeTableAdapter.Fill(hR_Dataset.Course_Attendee); } private void txt_ID_TextChanged(object sender, EventArgs e) { bool NewBio = false; if (formDataSource.Current != null) { if (((DataRowView)this.formDataSource.Current).Row["Attendee_Record"] == DBNull.Value) { AttendeeSearch Searching = new AttendeeSearch(); Searching.ShowDialog(); if (Searching.CourseAttendee.ID != 0) { ((DataRowView)this.formDataSource.Current).Row["Attendee_Record"] = Searching.CourseAttendee.ID; course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); int pos = formDataSource.Position; course_AttendeeTableAdapter.Fill(hR_Dataset.Course_Attendee); course_Attendee_BioTableAdapter1.Fill(hR_Dataset.Course_Attendee_Bio); } else { MessageBox.Show("You did not select or add an attendee, current record will now be removed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); formDataSource.RemoveCurrent(); } NewBio = true; } AttendeeID = (int)((DataRowView)this.formDataSource.Current).Row["Attendee_Record"]; LinkedBio = (from h in hR_Dataset.Course_Attendee_Bio where h.ID == AttendeeID select h).FirstOrDefault(); if (NewBio) { AttendeeInfo Info = new AttendeeInfo(LinkedBio); Info.ShowDialog(); txt_attendee.Text = Info.LinkedBio.FullName; NewBio = false; LinkedBio = (from h in hR_Dataset.Course_Attendee_Bio where h.ID == AttendeeID select h).FirstOrDefault(); } if (LinkedBio != null) { if (!LinkedBio.IsInternalPersonNull()) { RefreshRoleList(LinkedBio.InternalPerson.ToString()); if (combo_assosrole.Items.Count > 0) layout_assosrole.Visible = true; else layout_assosrole.Visible = false; SetExternalFields(false); } else { layout_assosrole.Visible = false; SetExternalFields(true); } txt_attendee.Text = LinkedBio.FullName; } } } private void bindingNavigator_Movement(object sender, MouseEventArgs e) { try { ToolStripButton nav = (ToolStripButton)sender; formDataSource.EndEdit(); DataTable CAttendeeTable = formDataSource.Table(); HR_Dataset.Course_AttendeeRow NextRole = hR_Dataset.Course_Attendee[formDataSource.Position]; TextInfo textInfo = new CultureInfo("en-GB", false).TextInfo; switch (nav.Text) { case "Move next": NextRole = hR_Dataset.Course_Attendee[formDataSource.Position + 1]; break; case "Move previous": NextRole = hR_Dataset.Course_Attendee[formDataSource.Position - 1]; break; case "Move last": NextRole = hR_Dataset.Course_Attendee.LastOrDefault(); break; case "Move first": NextRole = hR_Dataset.Course_Attendee.FirstOrDefault(); break; } if (NextRole.Lockedby == "") { if (Function.GetChangedColumns(hR_Dataset.Role, StringComparison.InvariantCultureIgnoreCase, true).Count > 0) { DialogResult R = MessageBox.Show("Do you want to save changes?", "Saving", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (R == DialogResult.Yes) { course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); switch (nav.Text) { case "Move next": formDataSource.MoveNext(); break; case "Move previous": formDataSource.MovePrevious(); break; case "Move last": formDataSource.MoveLast(); break; case "Move first": formDataSource.MoveFirst(); break; } } else if (R == DialogResult.No) { if (NewRecord) { formDataSource.RemoveCurrent(); course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); switch (nav.Text) { case "Move next": formDataSource.MoveNext(); break; case "Move previous": formDataSource.MovePrevious(); break; case "Move last": formDataSource.MoveLast(); break; case "Move first": formDataSource.MoveFirst(); break; } } else { hR_Dataset.Role.RejectChanges(); course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); switch (nav.Text) { case "Move next": formDataSource.MoveNext(); break; case "Move previous": formDataSource.MovePrevious(); break; case "Move last": formDataSource.MoveLast(); break; case "Move first": formDataSource.MoveFirst(); break; } } } else if (R == DialogResult.Cancel) { return; } } else { if (NewRecord) { DialogResult R = MessageBox.Show("Do you want to save changes?", "Saving", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (R == DialogResult.Yes) { course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); } else if (R == DialogResult.No) { formDataSource.RemoveCurrent(); course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); switch (nav.Text) { case "Move next": formDataSource.MoveNext(); break; case "Move previous": formDataSource.MovePrevious(); break; case "Move last": formDataSource.MoveLast(); break; case "Move first": formDataSource.MoveFirst(); break; } } } } } else { string[] Name = NextRole.Lockedby.Split('.'); MessageBox.Show("Record is currently locked by " + textInfo.ToTitleCase(Name[0]) + " " + textInfo.ToTitleCase(Name[1]), "Record is locked", MessageBoxButtons.OK, MessageBoxIcon.Warning); } AttendeeID = int.Parse(txt_ID.Text); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void Course_Attendee_FormClosing(object sender, FormClosingEventArgs e) { formDataSource.EndEdit(); AttendeeID = int.Parse(txt_ID.Text); switch (e.CloseReason) { case CloseReason.FormOwnerClosing: case CloseReason.TaskManagerClosing: case CloseReason.UserClosing: if (Function.GetChangedColumns(formDataSource.Table(), StringComparison.InvariantCultureIgnoreCase, true).Count > 0) { DialogResult R = MessageBox.Show("Do you want to save changes?", "Saving", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (R == DialogResult.Yes) { course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); } else if (R == DialogResult.No) { if (NewRecord) { formDataSource.RemoveCurrent(); course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); } else { hR_Dataset.Course_Attendee.RejectChanges(); } } else if (R == DialogResult.Cancel) { e.Cancel = true; } } else { if (NewRecord) { DialogResult R = MessageBox.Show("Do you want to save changes?", "Saving", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (R == DialogResult.Yes) { course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); } else if (R == DialogResult.No) { formDataSource.RemoveCurrent(); course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); } else if (R == DialogResult.Cancel) { e.Cancel = true; } } } break; case CloseReason.MdiFormClosing: case CloseReason.None: case CloseReason.ApplicationExitCall: case CloseReason.WindowsShutDown: course_AttendeeTableAdapter.Update((HR_Dataset.Course_AttendeeDataTable)formDataSource.Table()); break; } } }} 解决方案 Hello,Your code are written in the way when each change on the screen require to have an update from the server.If you want to reduce amount of request - make request managible. For example - on the changes start/re-start timer and du update on his ticks. You also can do some kind of local cache and synchronize cache with a server when you need sync. 这篇关于使用MS Access和C#Winforms加速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-26 23:51