When timer interval is short and timer tick run database operation and update asp.net web user interface, I can not type text or select DropDownList.
How to make not influence use's operation when it real time operate database?
If there are many users, I afraid influence the performance of database such as slow
i have set it update when change, but still quite often to intervene operation, such as i can not select dropdownlist or can not type in textbox
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
protected void Timer1_Tick(object sender, EventArgs e)
{
string[] last_serial_no = new string[Calculator_GridView.Rows.Count];
string[] last_a1_textbox = new string[Calculator_GridView.Rows.Count];
string[] last_b1_textbox = new string[Calculator_GridView.Rows.Count];
string[] last_mp_dropdown = new string[Calculator_GridView.Rows.Count];
bool change = false;
for (int i = 0; i < Calculator_GridView.Rows.Count; i++)
{
string serial_no = Calculator_GridView.Rows[i].Cells[1].Text;
string a1_textbox = Calculator_GridView.Rows[i].Cells[2].Text;
string b1_textbox = Calculator_GridView.Rows[i].Cells[3].Text;
DropDownList mp_dropdown = (DropDownList)Calculator_GridView.Rows[i].Cells[4].Controls[1];
//TextBox Result_textbox = (TextBox)Calculator_GridView.Rows[e.RowIndex].Cells[5].Controls[0];
if (last_serial_no[i] != serial_no ||
last_a1_textbox[i] != a1_textbox ||
last_b1_textbox[i] != b1_textbox ||
last_mp_dropdown[i] != mp_dropdown.SelectedValue)
开发者_JS百科 {
string executestring = "";
executestring = "Update cal set a1=" + a1_textbox;
executestring = executestring + ", b1=" + b1_textbox;
executestring = executestring + ", mp=" + mp_dropdown.SelectedValue;
executestring = executestring + ", result=" + (Convert.ToDouble(mp_dropdown.SelectedValue) * Convert.ToDouble(b1_textbox)).ToString();
executestring = executestring + " where [識別碼]=" + serial_no;
ExecuteDatabase(executestring);
change = true;
}
last_serial_no[i] = serial_no;
last_a1_textbox[i] = a1_textbox;
last_b1_textbox[i] = b1_textbox;
last_mp_dropdown[i] = mp_dropdown.SelectedValue;
}
if (change == true)
{
string connstr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/db1.mdb";
OleDbConnection conn = new OleDbConnection(connstr);
conn.ConnectionString = connstr;
try
{
conn.Open();
}
catch (Exception ex)
{
conn.Close();
}
OleDbCommand get_info_cmd = null;
get_info_cmd = new OleDbCommand("SELECT [識別碼], [a1], [b1], [result], [mp] FROM [cal]", conn);
OleDbDataReader get_info_Reader = get_info_cmd.ExecuteReader();
store.Columns.Add(new DataColumn("識別碼", typeof(int)));
store.Columns.Add(new DataColumn("a1", typeof(double)));
store.Columns.Add(new DataColumn("b1", typeof(double)));
store.Columns.Add(new DataColumn("mp", typeof(double)));
store.Columns.Add(new DataColumn("result", typeof(double)));
DataRow dr;
try
{
while (get_info_Reader.Read())
{
dr = store.NewRow();
dr[0] = get_info_Reader["識別碼"].ToString();
dr[1] = get_info_Reader["a1"].ToString();
dr[2] = get_info_Reader["b1"].ToString();
dr[3] = get_info_Reader["mp"].ToString();
dr[4] = (Convert.ToDouble(get_info_Reader["b1"].ToString()) * Convert.ToDouble(get_info_Reader["mp"].ToString())).ToString();
store.Rows.Add(dr);
}
}
catch (Exception ex)
{
Error_Label.Text = Error_Label.Text + ex.ToString();
conn.Close();
}
finally
{
get_info_cmd.Dispose();
get_info_Reader.Close();
conn.Close();
}
storeview = new DataView(store);
Calculator_GridView.Font.Size = new FontUnit(10);
Calculator_GridView.DataSourceID = "";
Calculator_GridView.DataSource = storeview;
Calculator_GridView.DataBind();
}
}
I reckon that you should be doing the DB operation in a seperate thread. Also, how are you updating the ASP.Net page as mentioned?
精彩评论