MySqlconnection不包含Connection,CommandText,Prepare或ExecuteNonquery的定义

时间:2012-09-26 20:39:50

标签: c# mysql

我正在使用http://zetcode.com/db/mysqlcsharptutorial/上的教程,我相信我已完全按照这些步骤操作,但我收到了这些错误。我已将MySql.Data,MySql.Data.Entity添加到引用中,但它仍然不允许我使用它。我搜索了这个问题,似乎无法得到明确的答案。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;
using MySql.Data.Entity;
using MySql.Data.Common;
using MySql.Data.Types;
using System.Configuration;
using System.Data.Common;

namespace Practice
{
    public class Example
    {
        public static void Main()
        {
            string cs = @"server=111.111.11.111; userid=11111111;password=111111;database=anydatabase";

            MySqlConnection conn = null;

            try
            {
                conn = new MySqlConnection(cs);
                conn.Open();

                MySqlConnection cmd = new MySqlConnection();
                cmd.Connection = conn;
                cmd.CommandText = "INSERT INT0 players(Anyone) VALUES(@Anyone)";
                cmd.Prepare();

                cmd.Parameters.AddWithValue("@Name", "Anyone New");
                cmd.ExecuteNonQuery();

            }
            catch (MySqlException ex)
            {
                Console.WriteLine("Error: (0)", ex.ToString());
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:2)

您正在寻找MySqlCommand

var cmd = new MySqlCommand();