private void toolStripButton2_Click(object sender, EventArgs e) { if (conStr == null) { toolStripButton1_Click(null, null); } if (conStr == null) { return; } richTextBox2.Text = ""; string s_sql = richTextBox1.SelectedText.Trim(); if (string.IsNullOrEmpty(s_sql)) { s_sql = richTextBox1.Text; } if (s_sql.ToLower().StartsWith("select")) { dataGridView1.DataSource = null; try { dataGridView1.DataSource = AppFunc.GetData(conStr, s_sql); tabControl1.SelectedIndex = 0; } catch (Exception ex) { richTextBox2.Text = ex.ToString(); tabControl1.SelectedIndex = 1; } } else { dataGridView1.DataSource = null; try { int ret = AppFunc.ExecuteNonQuery(conStr, s_sql); richTextBox2.Text = string.Format("执行语句成功,影响{0}行", ret); tabControl1.SelectedIndex = 1; } catch (Exception ex) { richTextBox2.Text = ex.ToString(); tabControl1.SelectedIndex = 1; } } }
private void button3_Click(object sender, EventArgs e) { ConStr = new DbConStrInfo { Server = tb_server.Text, Port = tb_port.Text, LogId = tb_logid.Text, LogPass = tb_logpass.Text, Database = cbb_db.Text, Provider = cbb_provider.Text }; if (AppFunc.TestConnect(ConStr)) { MessageBox.Show("连接数据库成功!", "提示信息"); } ConStr = null; }
private void button1_Click(object sender, EventArgs e) { ConStr = new DbConStrInfo { Server = tb_server.Text, Port = tb_port.Text, LogId = tb_logid.Text, LogPass = tb_logpass.Text, Database = cbb_db.Text, Provider = cbb_provider.Text }; if (!AppFunc.TestConnect(ConStr)) { ConStr = null; return; } SaveXml("db_config.xml"); this.DialogResult = DialogResult.OK; }
void LoadDb() { treeView1.Nodes.Clear(); string s_table = AppFunc.GetSql(conStr, 1); string s_view = AppFunc.GetSql(conStr, 2); DataTable table1 = AppFunc.GetData(conStr, s_table); DataTable table2 = AppFunc.GetData(conStr, s_view); TreeNode rootNode = new TreeNode(conStr.Database); var nodes = treeView1.Nodes.Find(conStr.Database, false); if (nodes != null && nodes.Length > 0) { rootNode = nodes[0]; } else { treeView1.Nodes.Add(rootNode); } SetTreeview(1, rootNode, table1); SetTreeview(2, rootNode, table2); }