09-数据库操作/读取数据库表结构/GetDataStruct/Form1.cs

(开头部分) 6KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace GetDataStruct
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            SQLDMO.Application SQLServer = new SQLDMO.Application();
            SQLDMO.NameList strServerList = SQLServer.ListAvailableSQLServers();
            if (strServerList.Count > 0)
            {
                for (int i = 0; i < strServerList.Count; i++)
                {
                    toolStripTextBox1.Items.Add(strServerList.Item(i + 1));
                }
            }
            toolStripTextBox1.Text = "(local)";
            comboBox2.SelectedIndex = 0;
            toolStripTextBox3.TextBox.PasswordChar = '*';
        }

        private void toolStripTextBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                toolStripTextBox3.Focus();
        }

        private void toolStripTextBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                toolStripButton1_Click(sender, e);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                string str = "Data Source=" + toolStripTextBox1.Text + ";database=master;Uid=" + toolStripTextBox2.Text + ";Pwd=" + toolStripTextBox3.Text + ";";
                comboBox1.DataSource = getTable(str, "select name from sysdatabases", "sysdatabases");
                comboBox1.DisplayMember = "name";
                comboBox1.ValueMember = "name";
                button1.Enabled = button2.Enabled = button3.Enabled = true;
            }
            catch { }
        }

后面还有 100 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读 AI

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。