08-28-2012, 08:34 PM
Hey, im Trying to use my MySQL Connection string, with Strings so without that i need to write" host = "127.0.0.1" "
but there are a little Problem i hope some of you can find it^^
The Error: The connection property has not been set or is null.
// Make the Strings
public partial class user_index : Form
{
public string host;
public string user;
public string db;
public string pw;
public user_index()
{
InitializeComponent();
Initialize();
}
//Initialize the Strings (and define)
private void Initialize()
{
Form1 f1 = new Form1();
host = f1.textBox1.Text;
user = f1.textBox3.Text;
db = f1.textBox5.Text;
pw = f1.textBox4.Text;
}
//Insert
public void Insert()
{
MySqlConnection con;
MySqlConnectionStringBuilder csb = new MySqlConnectionStringBuilder();
csb.Server = host;
csb.UserID = user;
csb.Database = db;
csb.Password = pw;
con = new MySqlConnection(csb.ConnectionString);
MySqlConnection connection = new MySqlConnection(csb.ConnectionString);
DataTable datatable = new DataTable();
String sql1 = "SELECT * FROM t_characters user_code WHERE a_nick =" + textBox1.Text;
MySqlDataAdapter dataAdapter = new MySqlDataAdapter(sql1, connection);
dataAdapter.Fill(datatable);
foreach (DataRow row in datatable.Rows)
{
ListViewItem item = new ListViewItem(
new string[] {
row["a_user_index"].ToString()});
listView1.Items.Add(item);
}
}

