Quantcast
Channel: Questions in topic: "namespace"
Viewing all articles
Browse latest Browse all 398

Namespace not recognized even its added

$
0
0
im making an AR application using unity and vuforia as my graduation project, so im not so experienced in unity and C#. everything is going smooth till i reached DB, now im trying to connect MySql DB to Unity and found this code some where in internet. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.Windows; using MySql.Data.MySqlClient; public class DBConnect : MonoBehaviour { private MySqlConnection connection; private string server; private string database; private string uid; private string password; //Constructor public DBConnect() { Initialize(); } //Initialize values private void Initialize() { server = "localhost"; database = "3datlas_db"; uid = "root"; password = "root"; string connectionString; connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";"; connection = new MySqlConnection(connectionString); } //open connection to database private bool OpenConnection() { try { connection.Open(); return true; } catch (MySqlException ex) { //When handling errors, you can your application's response based //on the error number. //The two most common error numbers when connecting are as follows: //0: Cannot connect to server. //1045: Invalid user name and/or password. switch (ex.Number) { case 0: // MessageBox.Show("Cannot connect to server. Contact administrator"); break; case 1045: // MessageBox.Show("Invalid username/password, please try again"); break; } return false; } } //Close connection private bool CloseConnection() { try { connection.Close(); return true; } catch (MySqlException ex) { //MessageBox.Show(ex.Message); return false; } } //Insert statement public void Insert() { string query = "INSERT INTO tableinfo (name, age) VALUES('John Smith', '33')"; //open connection if (this.OpenConnection() == true) { //create command and assign the query and connection from the constructor MySqlCommand cmd = new MySqlCommand(query, connection); //Execute command cmd.ExecuteNonQuery(); //close connection this.CloseConnection(); } } //Update statement public void Update() { string query = "UPDATE tableinfo SET name='Joe', age='22' WHERE name='John Smith'"; //Open connection if (this.OpenConnection() == true) { //create mysql command MySqlCommand cmd = new MySqlCommand(); //Assign the query using CommandText cmd.CommandText = query; //Assign the connection using Connection cmd.Connection = connection; //Execute query cmd.ExecuteNonQuery(); //close connection this.CloseConnection(); } } //Delete statement public void Delete() { string query = "DELETE FROM tableinfo WHERE name='John Smith'"; if (this.OpenConnection() == true) { MySqlCommand cmd = new MySqlCommand(query, connection); cmd.ExecuteNonQuery(); this.CloseConnection(); } } //Select statement public List[] Select() { string query = "SELECT * FROM tableinfo"; //Create a list to store the result List[] list = new List[3]; list[0] = new List(); list[1] = new List(); list[2] = new List(); //Open connection if (this.OpenConnection() == true) { //Create Command MySqlCommand cmd = new MySqlCommand(query, connection); //Create a data reader and Execute the command MySqlDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { list[0].Add(dataReader["id"] + ""); list[1].Add(dataReader["name"] + ""); list[2].Add(dataReader["age"] + ""); } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); //return list to be displayed return list; } else { return list; } } } which is working till i found few errors: 1- Assets/DBconnection.cs(6,7): error CS0246: The type or namespace name `MySql' could not be found. Are you missing an assembly reference? 2- Assets/DBconnection.cs(11,13): error CS0246: The type or namespace name `MySqlConnection' could not be found. Are you missing an assembly reference? 3- Assets/DBconnection.cs(5,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference? i have already added the necessary references but the problem is still there. i tried to search the internet but all of them saying to add references or to copy the necessary Dll files to assets folder in unity which i tried but still didn't work. help plz :(

Viewing all articles
Browse latest Browse all 398

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>