使用后台线程备份单个数据表
2008-11-06 11:16
337 查看
private void 备份数据ToolStripMenuItem1_Click(object sender, EventArgs e)//使用线程进行备份 { Thread t = new Thread(new ThreadStart(BackUpProcess)); t.Start(); } private void BackUpProcess() { string[] m_TableName ={ "Table2","Table1", "Logon" }; try { if (MessageBox.Show("确定要备份数据到E盘吗?", "备份数据", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { this.Cursor = Cursors.WaitCursor; for (int i = 0; i < m_TableName.Length; i++) { string sql; sql = "EXEC master..xp_cmdshell 'bcp LightCtrDB.dbo." + m_TableName[i] + " out E://" + m_TableName[i] + ".txt -c -S QRSHZL -U sa -P 123'"; G_SqlExecute.GetExecute(sql); double percentDone = ((Convert.ToDouble(i + 1) / m_TableName.Length) * 100); UpdateProcess(percentDone); } MessageBox.Show("备份数据表成功!"); } else { MessageBox.Show("备份数据失败!"); } } catch (Exception ex) { MessageBox.Show("错误" + ex.ToString()); } finally { this.Cursor = Cursors.Default; toolStripStatusLabel7.Text = null; ProgressBar1.Value = 0; } } private delegate void UpdateProgressDeletegate(double percentDone); protected void UpdateProcess(double percentDone) { if (InvokeRequired == true)//判断是 主线程还是其他线程。 { BeginInvoke( new UpdateProgressDeletegate(UpdateProcess), new object[] { percentDone }); return; } ProgressBar1.Value = Convert.ToInt32(percentDone); toolStripStatusLabel7.Text = ProgressBar1.Value.ToString() + "% Complete!"; if (percentDone == 0) { toolStripStatusLabel7.Text = string.Empty; } }
相关文章推荐
- 第02讲:正确使用织梦(DEDECMS)后台的数据备份与还原功能
- 通过模仿AsyncTask的封装方式,实现一个后台预读数据的线程,(使用AsyncTask有导致应用FC的风险)
- 使用Handy Backup 6.2进行数据备份与还原(多图)
- 使用js动态添加文本框 并在后台取文本框数据
- vue使用ajax获取后台数据进行显示
- linux 平台下 postgres 使用 (安装 启动 关闭 数据备份 还原)
- jsp页面使用json后台数据
- [ORACLE]通用备份数据存储过程,适合编辑/删除前需要备份数据时使用
- 使用MYSQL备份数据恢复
- ORACLE模拟一个数据文件坏块并使用RMAN备份来恢复
- cPanel面板-如何使用R1soft数据备份服务使用说明图解
- 在使用ajax向后台发送json数据,存在格式不正确的问题
- 使用dd备份和恢复ASM中的数据文件头
- ThinkPHP定时ajax获取后台数据,使用javascript动态修改前端页面的表格来显示数据
- ASPNET中实现在线用户检测(使用后台守护线程)
- ajax 请求后台数据(及使用FormData对象提交表单及上传图片)
- ASP.NET中使用JSON方便实现前台与后台的数据交换
- 使用批处理异地备份数据
- 使用WinDbg查看非当前线程所在模块的内存数据信息
- 使用后台代码实现Gridview显示sql数据