|
using System;
using System.Windows.Forms;
namespace AddressBook
{
public partial class frmMySQLSetting : Form
{
MySql.Data.MySqlClient.MySqlConnection ConnectDB;
public frmMySQLSetting()
{
InitializeComponent();
if (((ConnectionTypes)DataConnection.ConnectionType) == ConnectionTypes.MySQLConnection)
{
txtDataSource.Text = DataConnection.DataSource;
txtUserName.Text = DataConnection.UserName;
txtPassword.Text = DataConnection.Password;
GetDBNames();
lstDatabaseList.SelectedItem = DataConnection.Database;
}
}
void GetDBNames(object sender, EventArgs e)
{
GetDBNames();
}
void GetDBNames()
{
lstDatabaseList.Items.Clear();
ConnectDB = new MySql.Data.MySqlClient.MySqlConnection(ConnectionString);
try
{
ConnectDB.Open();
}
catch (Exception) { return; }
MySql.Data.MySqlClient.MySqlCommand ExecCmd = new MySql.Data.MySqlClient.MySqlCommand("SHOW DATABASES", ConnectDB);
MySql.Data.MySqlClient.MySqlDataReader Reader = ExecCmd.ExecuteReader();
while (Reader.Read())
{
lstDatabaseList.Items.Add(Reader.GetString(0));
}
ConnectDB.Close();
}
string ConnectionString
{
get
{
return "server=" + txtDataSource.Text + ";Database=MySql;User ID=" + txtUserName.Text + ";pooling=false;Password=" + txtPassword.Text;
}
}
void SaveChanges(object sender, EventArgs e)
{
if (lstDatabaseList.SelectedItem == null) { MessageBox.Show("Please select a valid connection configuration.", "Invalid Connection"); return; }
DataConnection.ConnectionType = (int)ConnectionTypes.MySQLConnection;
DataConnection.DataSource = txtDataSource.Text;
DataConnection.Database = lstDatabaseList.SelectedItem.ToString();
DataConnection.UserName = txtUserName.Text;
DataConnection.Password = txtPassword.Text;
DataConnection.SaveSettings();
}
void ChangesMade(object sender, EventArgs e)
{
lstDatabaseList.Items.Clear();
}
void Cancel_Click(object sender, EventArgs e)
{
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.
Completed B.Com(CS) at DGVC and GNIIT Software Engineering at NIIT. Resident at Chennai and working as a Software Engineer.
Language / Technology :
C#, ADO.NET, ASP.NET, MVC, WCF, ASP, PHP, XML, Java, J2EE, HTML, JavaScript, JQuery, AngularJS, VB Script, C++, MS SQL Server, SSRS, MySql, Oracle, Oracle Forms Development, Windows, Linux.
Click here to view other articles.
Mail Me at: shridhar_tl@ymail.com
Visit my Site: www.iCodeIt.in