📄 dmxadhoc.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.AnalysisServices.AdomdClient;
namespace Chapter20WinClient
{
public partial class frmDMXAdHoc : Form
{
public frmDMXAdHoc()
{
InitializeComponent();
}
private void btnExecute_Click(object sender, EventArgs e)
{
// Execute DMX query using AdomdDataAdapter.Fill;
Cursor.Current = Cursors.WaitCursor;
AdomdConnection conn = new AdomdConnection("Data Source=" + txtServer.Text + ";Initial Catalog=" + cboCatalogs.Text);
AdomdCommand cmd = new AdomdCommand(txtQuery.Text, conn);
AdomdDataAdapter da = new AdomdDataAdapter(cmd);
DataTable dt = new DataTable();
try
{
da.Fill(dt);
dgvResults.DataSource = dt;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
// UI
Cursor.Current = Cursors.Default;
}
private void btnGetCatalogs_Click(object sender, EventArgs e)
{
// UI
cboCatalogs.Items.Clear();
txtQuery.Enabled = false;
btnExecute.Enabled = false;
// Declare and initialize AdomdConnection object:
AdomdConnection conn = new AdomdConnection("Data Source=" + txtServer.Text);
// Fetch all catalogs in specifed database using GetSchemaDataSet
try
{
conn.Open();
foreach (DataRow dr in conn.GetSchemaDataSet(AdomdSchemaGuid.Catalogs, null).Tables[0].Rows)
{
cboCatalogs.Items.Add((string)dr[0]);
}
lblDatabase.Enabled = true;
cboCatalogs.Enabled = true;
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void cboCatalogs_SelectedIndexChanged(object sender, EventArgs e)
{
// Once database is selected, user may specify and run a DMX query
txtQuery.Enabled = true;
btnExecute.Enabled = true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -