I am working with the tutorial at http://zetcode.com/db/mysqlcsharptutorial/, I believe I have followed the steps exactly, yet I am getting these errors. I have added MySql.Data, MySql.Data.Entity to the references yet it still doesn’t allow me to use it. I have googled the issue and can’t seem to get a clear answer.
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();
}
}
}
}
}
You’re looking for
MySqlCommand.