좋아요. 기본적으로 PhpMyAdmin에서 MySQL 테이블을 만들었습니다. 로컬 호스트, 사용자 이름 루트 및 암호 없음.Visual C# Express 2008과의 MySQL 연결
Visual Express 2008의 C#을 기반으로하는 Windows 응용 프로그램에서 작업하고 있습니다. 다음과 같은 코드를 사용하여 MySQL에서 데이터를 저장 /로드 할 수 있습니다 (이 링크로 이동하려면/tuts를 따라 가야합니다. 그러나 이것이 이론적으로 MySQL @ phpmyadmin에 어떻게 연결될 수 있는지 모르겠다. 나는 PhpmyAdmin 데이터베이스와 참조에서 다운로드하거나 스크립트 또는 뭔가 플러그인으로 추가 할 파일이 필요 없다는 것을 의미합니까? Tottaly lost ..) :
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;
}
}
실행할 때 내 데이터를 입력하고 단추를 클릭하면 온라인에이 오류가 표시됩니다 (MySqlConnection mcon = new MySqlConnection (connString);).* 키워드가 지원되지 않습니다. 매개 변수 이름 : id *
완벽하게 MySQL에 연결하는 방법을 알려주십시오. 또한 MySQL Connector를 다운로드하고 mysql.data.dll 파일을 참조했습니다. 그래서 그 부분은
대런 디미트로프 감사합니다! 그게 다 고쳐! !!!!! 나는 이것을 알아 내려고 노력하는 하루처럼 보냈지 만, 당신은 그저 나를 도왔습니다 !! : D – DamageDz
@DamageDz, 좋아요, 제가 도울 수있어서 기쁩니다. 이 게시물이 도움이 되었다면 [대답으로 표시] (http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)를 고려해 보시기 바랍니다. 그것. –
@vucetica, ADO.NET은 연결 풀을 관리합니다. 따라서 두 번째'using' 블록 **은 데이터베이스에 새로운 연결 **을 열지 않습니다. [연결 풀] (http://dev.mysql.com/doc/refman/5.0/en/connector-net-programming-connection-pooling.html)에서 기존 연결을 그립니다. using 문의 끝에서 연결은 닫히지 않지만 재사용하기 위해 연결 풀로 리턴됩니다. 두 번째 발언에 관한 한, 나는 나의 신청서에있는 우려를 분리하는 것을 선호한다. 두 사람은 일반적으로 나중에 완전히 재사용 할 수있는 완전히 별개의 두 가지 방법으로 이동합니다. –