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");
}
}
}
}
Loading
Moses SpencerPosted Mar 19, 2015, 5:17 AM
For example if you have something like the following INI content:
server ip = localhost
database = pxi
username = root
password =
Then you would use the following:
Jan MontanoPosted Mar 16, 2009, 10:42 PM
Here's an article regarding how to read/write xml ini files. Good luck!
Joshua SparksPosted Mar 16, 2009, 3:34 PM
How do I add the variables so they are replaced by the lines in the ini file ?
Vijaya KadiyalaPosted Mar 16, 2009, 1:35 PM
In your requirement you can't use web.config. By looking at the code you have problem in writing/reading the data from a .ini file..
Check out the below link which will help you to read and write.
http://www.csharp-station.com/HowTo/ReadWriteTextFile.aspx
Once you are done with this then we can start querying the data.
Thanks
-- Vijaya Kadiyalahttp
://dotnetvj.blogspot.comJoshua SparksPosted Mar 16, 2009, 1:05 PM
Yes it is dynamic, I want the user to beable to connect to what sql server they wish to. I.E they have my tool on thier pc but the database server on another I want them to be able connect to that database server.
I have never heard of using a web.config file ... as I said I am new to programming.
Vijaya KadiyalaPosted Mar 16, 2009, 12:52 PM
Hi,
Instead of storign this information in .ini file!! why can't you store this in web.config file!! why are you giving an option to the use to enter IP,Database etc information?? is this dynamic??
Thanks -- Vijaya Kadiyala
http://dotnetvj.blogspot.com