Exemplo n.º 1
0
        //直连Mysql
        private void ButtonConnectMysql_Click(object sender, RoutedEventArgs e)
        {
            WindowConnDB connDB = new WindowConnDB("mysql");

            connDB.ShowDialog();
            datasetListView.RefreshDB(MyTrees.treeDB, "");
        }
Exemplo n.º 2
0
        public bool ExportData(StreamWriter mysw, List <string> headCols, string tab, WindowConnDB win)
        {
            bool result = false;
            int  allRow = 0;
            int  row    = 0;

            //保存到tab文件中,以tab键分割
            try
            {
                //先查出总数量
                conn.Open();
                cmd.CommandText = "select count(*) from " + tab;
                SqlDataReader sdr = cmd.ExecuteReader();
                sdr.Read();
                allRow = sdr.GetInt32(0);
                sdr.Close();

                //再查询所有的数据
                cmd.CommandText = "select " + string.Join(",", headCols) + " from " + tab;
                sdr             = cmd.ExecuteReader();


                int      step = allRow > 100 ? allRow / 100 : 1;
                object[] objs = new object[sdr.FieldCount];

                while (sdr.Read())
                {
                    sdr.GetValues(objs);
                    for (int i = 0; i < objs.Length; i++)
                    {
                        string obj = objs[i].ToString();
                        if (obj.Contains("\t"))
                        {
                            objs[i] = obj.Replace("\t", " ");
                        }
                    }
                    string line = string.Join("\t", objs);
                    mysw.WriteLine(line);

                    row++;
                    if (row % step == 0)
                    {
                        win.prograss.Value    = (int)(100.0 * row / allRow);
                        win.labelMessage.Text = "正在导出第" + row + "(总共" + allRow + ")";
                        win.DoEvents();
                    }
                }

                sdr.Close();
                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                win.prograss.Visibility = Visibility.Hidden;
                win.labelMessage.Text   = "导出完成!一共导出" + row + "(总共" + allRow + ")";
                conn.Close();
                mysw.Close();
            }
            return(result);
        }