6
Reply

Using an .ini file ??!!??

Joshua Sparks

Joshua Sparks

Mar 16 2009 12:22 PM
6.3k
What I am trying to do, is allow the user to set the server ip, port, database and username in an .ini file.
Then I Am trying to take that info and import it into my c# code. I am new to c# so please be gentle .... Here is my code thus far

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 MySql.Data.MySqlClient;

namespace Pxi_Gm_Tool
{
    public partial class addAccounts : Form
    {
        public addAccounts()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void addAccounts_Load(object sender, EventArgs e)
        {
            MySqlConnectionStringBuilder connBuilder =
                new MySqlConnectionStringBuilder();

            connBuilder.Add("Database", "pxi");
            connBuilder.Add("Data Source", "localhost");
            connBuilder.Add("User Id", "root");
            connBuilder.Add("Password", "");

            MySqlConnection connection =
                new MySqlConnection(connBuilder.ConnectionString);
            MySqlCommand cmd = connection.CreateCommand();
            MySqlCommand command = connection.CreateCommand();
            connection.Open();
            try
            {
                command.CommandText = "INSERT INTO accounts (aident, pass, privs,status,created) VALUES (textbox1.text, textbox2.text, 5, 0, CURRENT_TIMESTAMP)";
                connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Username in use");
            }
        }
    }
}




Answers (6)
Next Recommended Forum