?? form1.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace AttachDb
{
/// <summary>
/// Form1 的摘要說明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
/// <summary>
/// 必需的設(shè)計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗體設(shè)計器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
//
}
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗體設(shè)計器生成的代碼
/// <summary>
/// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 104);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(232, 40);
this.button1.TabIndex = 0;
this.button1.Text = "選擇mdf文件并附加";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(136, 10);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(66, 17);
this.label1.TabIndex = 1;
this.label1.Text = "數(shù)據(jù)庫名:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(144, 40);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(54, 17);
this.label2.TabIndex = 2;
this.label2.Text = "登錄名:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(136, 72);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(66, 17);
this.label3.TabIndex = 3;
this.label3.Text = "登錄密碼:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(208, 8);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 4;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(208, 38);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 5;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(208, 70);
this.textBox3.Name = "textBox3";
this.textBox3.TabIndex = 6;
this.textBox3.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(458, 160);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Microsoft SQL Server 附加 *******雄宗舜*******";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 應(yīng)用程序的主入口點。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
if (textBox1.Text=="")
MessageBox.Show("數(shù)據(jù)庫名呢?");
else if (textBox2.Text=="")
MessageBox.Show("登陸名呢?");
else
{
OpenFileDialog ofdlg=new OpenFileDialog();
ofdlg.Filter="*.mdf|*.mdf";
if(ofdlg.ShowDialog()==DialogResult.Cancel)return;
FaibClass.SqlDMO.SQLServer sq=new FaibClass.SqlDMO.SQLServer();
sq.Connect("(local)");
//if(sq.AttachDatabase("equip",ofdlg.FileName,"equip_loginer","wise7794"));
/*
Parameters附加數(shù)據(jù)庫
DatabaseName
數(shù)據(jù)庫名稱。
DBFileName
數(shù)據(jù)文件路徑。
LoginName
登錄名。
Password
登錄密碼。
*/
MessageBox.Show("數(shù)據(jù)庫名為:"+textBox1.Text.ToString()+" || 路徑為:"+ofdlg.FileName+" || 登錄用戶名為:"+textBox2.Text.ToString()+" || 登錄密碼為:"+textBox3.Text.ToString());
if(sq.AttachDatabase(textBox1.Text.ToString(),ofdlg.FileName,textBox2.Text.ToString(),textBox3.Text.ToString()))
MessageBox.Show("附加成功");
else
MessageBox.Show("媽的,搞不成!");
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -