Ok So Basically I have made MySQL table on PhpMyAdmin. It’s on local host, username root and no password.
I’m working on a Windows Application based on c# on visual express 2008. I have the following code for a button to save/load data from the MySQL(I have followed some links/tuts to get to this point, but dunno how this can theoritically connect to the MySQL @ phpmyadmin, I mean Dont I need a file to download from PhpmyAdmin database and reference or add it as a plugin to the script or something? Tottaly lost here..):
String connString = "SERVER = localhost; DATABASE = request; User ID = root; ID =; UserName =; Date =; Type =; Rules =;";
MySqlConnection mcon = new MySqlConnection(connString);
String command = "SELECT * FROM requesttcw";
MySqlCommand cmd = new MySqlCommand(command, mcon);
MySqlDataReader reader;
try
{
mcon.Open();
cmd.ExecuteNonQuery();
reader = cmd.ExecuteReader();
cmd.CommandType = System.Data.CommandType.Text;
while (reader.Read() != false)
{
Console.WriteLine(reader["ID"]);
Console.WriteLine(reader["ClanName"]);
Console.WriteLine(reader["Date"]);
Console.WriteLine(reader["Type"]);
Console.WriteLine(reader["Rules"]);
}
Console.ReadLine();
}
catch (Exception)
{
MessageBox.Show("ERROR: There was an error trying to connect to the DB!");
return;
}
cmd.CommandText = "INSERT INTO requesttcw (ClanName, Date, Type, Rules) VALUES ('" + textBox1.Text + "', '" + textBox2.Text + "', '" + textBox3.Text + "', '" + richTextBox1.Text + "' LIMIT 1)";
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("You're Request Has Been Posted!");
}
catch (Exception ex)
{
string message = ("ERROR: There was an error submitting your form!" + ex + "");
DialogResult result = MessageBox.Show(message, "ERROR", MessageBoxButtons.RetryCancel, MessageBoxIcon.Question);
switch (result)
{
case DialogResult.Retry:
Application.Restart();
break;
case DialogResult.Cancel:
this.Close();
break;
}
}
When I run it, enter my data, and click the button, It gives me this error on line(MySqlConnection mcon = new MySqlConnection(connString);
*
Keyword not supported.
Parameter name: id
*
Please tell me how to fully connect this to the MySQL.. I have also downloaded the MySQL Connector and referenced the mysql.data.dll file. So that part is done too…
Try the following connection string:
Also try cleaning your code and ensure that you are properly disposing
IDispoableresources such as SQL connections and commands by wrapping them inusingstatements. Also make sure that you are using prepared statements or your code is vulnerable to SQL injection attacks and your database could be ruined very quickly (in a blink of an eye):As far as exception handling is concerned, I have omitted it in my example but you could obviously wrap the
usingstatements in try/catch blocks.