Пример #1
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (cboServer.Text == string.Empty)
            {
                MessageBox.Show("请选择要执行的服务器");
                return;
            }
            if (txtSql.Text.Trim() == string.Empty)
            {
                MessageBox.Show("请选择要执行的语句");
                return;
            }
            TreeNode treeNode = tvwAnalyze.SelectedNode;
            DataRow  dr       = treeNode.Tag as DataRow;

            if (dr != null)
            {
                string    strDbType     = dr["DbType"].ToString();
                string    strExcuteType = dr["ExcuteType"].ToString();
                TreeNode  treeNodeFind  = FindTreeNodeByName(cboServer.Text.Trim());
                ServerTag serverTag     = treeNodeFind.Tag as ServerTag;
                if (serverTag != null)
                {
                    SqlType dbType = GetSqlType(strDbType);
                    if (serverTag.DBType != dbType)
                    {
                        MessageBox.Show("选中的语句不支持在" + serverTag.DBType + "服务器下执行");
                        return;
                    }
                    IDBHelper dbHelper = DataBaseManager.GetDbHelper(dbType, serverTag.MasterConn);
                    switch (strExcuteType)
                    {
                    case "SQL语句":
                        dbHelper.CreateCommand(txtSql.Text.Trim());
                        break;

                    case "存储过程":
                        dbHelper.CreateStoredCommand(txtSql.Text.Trim());
                        break;
                    }
                    DataSet ds = dbHelper.ExecuteQueryDataSet();
                    if (ds.Tables.Count > 0)
                    {
                        grdResult.DataSource = ds.Tables[0];
                    }
                }
            }
        }