|
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data.SqlTypes;
namespace MSDEGUI
{
/// <summary>
/// Summary description for ConnStrDlg.
/// </summary>
public class ConnStrDlg : System.Windows.Forms.Form
{
public string m_sConnStr = "";
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtConnStr;
private System.Windows.Forms.Button btnTest;
private System.Windows.Forms.Button btnAccept;
private System.Windows.Forms.Button btnCancel;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public ConnStrDlg()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.txtConnStr = new System.Windows.Forms.TextBox();
this.btnTest = new System.Windows.Forms.Button();
this.btnAccept = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(128, 16);
this.label1.TabIndex = 0;
this.label1.Text = "Enter data source";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// txtConnStr
//
this.txtConnStr.Location = new System.Drawing.Point(104, 8);
this.txtConnStr.Name = "txtConnStr";
this.txtConnStr.Size = new System.Drawing.Size(176, 20);
this.txtConnStr.TabIndex = 1;
this.txtConnStr.Text = "";
//
// btnTest
//
this.btnTest.Location = new System.Drawing.Point(16, 48);
this.btnTest.Name = "btnTest";
this.btnTest.TabIndex = 2;
this.btnTest.Text = "Test";
this.btnTest.Click += new System.EventHandler(this.OnTest);
//
// btnAccept
//
this.btnAccept.Location = new System.Drawing.Point(112, 48);
this.btnAccept.Name = "btnAccept";
this.btnAccept.TabIndex = 3;
this.btnAccept.Text = "Accept";
this.btnAccept.Click += new System.EventHandler(this.OnAccept);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(208, 48);
this.btnCancel.Name = "btnCancel";
this.btnCancel.TabIndex = 4;
this.btnCancel.Text = "Cancel";
this.btnCancel.Click += new System.EventHandler(this.OnCancel);
//
// ConnStrDlg
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(296, 77);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnCancel,
this.btnAccept,
this.btnTest,
this.txtConnStr,
this.label1});
this.Name = "ConnStrDlg";
this.Text = "Connection String Entry";
this.ResumeLayout(false);
}
#endregion
private void OnTest(object sender, System.EventArgs e)
{
try
{
SqlConnection sqlConn = new SqlConnection("Data Source=" + txtConnStr.Text + ";Trusted_Connection=Yes;");
sqlConn.Open();
sqlConn.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
MessageBox.Show("Connection Successful");
}
private void OnAccept(object sender, System.EventArgs e)
{
try
{
SqlConnection sqlConn = new SqlConnection("Data Source=" + txtConnStr.Text + ";Trusted_Connection=Yes;");
sqlConn.Open();
sqlConn.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
this.Close();
return;
}
m_sConnStr = "Data Source=" + txtConnStr.Text + ";Trusted_Connection=Yes;";
this.Close();
}
private void OnCancel(object sender, System.EventArgs e)
{
this.Close();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Programming computers ( self taught ) since about 1984 when I bought my first Apple ][. Was working on a GUI library to interface Win32 to Python, and writing graphics filters in my spare time, and then building n-tiered apps using asp, atl and asp.net in my job at Dytech. After 4 years there, I've started working from home, at first for Code Project and now for a vet telemedicine company. I owned part of a company that sells client education software in the vet market, but we sold that and I worked for the owners for five years before leaving to get away from the travel, and spend more time with my family. I now work for a company here in Hobart, doing all sorts of Microsoft based stuff in C++ and C#, with a lot of T-SQL in the mix.