• 大小: 384KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-27
  • 语言: C#
  • 标签: C#  WinForm  Sqlserver  

资源简介

根据SQL SERVER Management登陆界面制作了一个类似于窗体,无非是用C#语言实现,写这个程序原目的是很多人都不会连接数据库,你可以看看我的代码,其实就是那么几行。

资源截图

代码片段和文件信息

using System;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
using System.Windows.Forms;

namespace WinFormLoginSqlServer
{
    public partial class LoginForm : Form
    {
        private bool bIdentity;//基本身份验证
        public LoginForm()
        {
            InitializeComponent();
        }

        private void LoginForm_Load(object sender EventArgs e)
        {
            cbServerType.Items.Add(“数据库搜索引擎“);
            cbServerType.SelectedIndex = 0;

            cbServerName.Items.Add(“localhost“);
            cbServerName.SelectedIndex = 0;

            cbIdentity.Items.Add(“基本身份验证“);
            cbIdentity.Items.Add(“Windows 身份验证“);
            cbIdentity.SelectedIndex = 0;
        }

        private void cbIdentity_SelectedIndexChanged(object sender EventArgs e)
        {
            if (cbIdentity.SelectedIndex == 0)
            {
                bIdentity = true;
                txtName.Enabled = txtPassword.Enabled = true;
            }
            else
            {
                bIdentity = false;
                txtName.Enabled = txtPassword.Enabled = false;
            }
        }

        private void btnExit_Click(object sender EventArgs e)
        {
            Application.Exit();
        }

        private void btnGo_Click(object sender EventArgs e)
        {
            string s = ““;
            if (bIdentity)
            {
                s = “server=“ + cbServerName.Text + “;uid=“ + txtName.Text + “;password=“ + txtPassword.Text + “;database=master;“;
            }
            else
            {
                s = “Data Source=“ + cbServerName.Text + “;Integrated Security=SSPI;Initial Catalog=master;“;
            }
            try
            {
                SqlConnection con = new SqlConnection(s);
                con.Open();
                con.Close();
                lbString.Width = s.Length;
                lbString.Text = “DB:“ + s;
                //Clipboard.SetDataobject(s);
            }
            catch (Exception ex)
            {
                lbString.Text = ex.Message.Substring(0 ex.Message.IndexOf(‘。‘));
            }
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        492  2009-02-25 07:45  Program.cs

     文件       3269  2009-02-25 09:00  WinFormLoginSqlServer.csproj

     文件       1080  2009-02-25 07:44  WinFormLoginSqlServer.sln

    ..A..H.     19968  2009-02-25 09:15  WinFormLoginSqlServer.suo

     目录          0  2009-02-25 07:45  bin

     目录          0  2009-02-25 08:03  bin\Debug

     文件     700416  2009-02-25 09:01  bin\Debug\WinFormLoginSqlServer.exe

     文件      26112  2009-02-25 09:01  bin\Debug\WinFormLoginSqlServer.pdb

     文件       5632  2005-09-23 06:56  bin\Debug\WinFormLoginSqlServer.vshost.exe

     目录          0  2009-02-25 08:03  obj

     目录          0  2009-02-25 09:01  obj\Debug

     目录          0  2009-02-25 07:45  obj\Debug\Refactor

     目录          0  2009-02-25 07:44  obj\Debug\TempPE

     文件        846  2009-02-25 08:51  obj\Debug\WinFormLoginSqlServer.csproj.GenerateResource.Cache

     文件     700416  2009-02-25 09:01  obj\Debug\WinFormLoginSqlServer.exe

     文件     677676  2009-02-25 08:51  obj\Debug\WinFormLoginSqlServer.LoginForm.resources

     文件      26112  2009-02-25 09:01  obj\Debug\WinFormLoginSqlServer.pdb

     文件        180  2009-02-25 08:03  obj\Debug\WinFormLoginSqlServer.Properties.Resources.resources

     文件        746  2009-02-25 09:11  obj\WinFormLoginSqlServer.csproj.FileListAbsolute.txt

     目录          0  2009-02-25 07:44  Properties

     文件       1302  2009-02-25 07:44  Properties\AssemblyInfo.cs

     文件       2871  2009-02-25 07:44  Properties\Resources.Designer.cs

     文件       5612  2009-02-25 07:44  Properties\Resources.resx

     文件       1106  2009-02-25 07:44  Properties\Settings.Designer.cs

     文件        249  2009-02-25 07:44  Properties\Settings.settings

     文件       2248  2009-02-25 09:01  LoginForm.cs

     文件      10321  2009-02-25 08:51  LoginForm.Designer.cs

     文件    1022082  2009-02-25 08:51  LoginForm.resx

----------- ---------  ---------- -----  ----

              3208736                    28

............此处省略1个文件信息

评论

共有 条评论