Hi,
I am coding a game under Unity 3D
But i have a problem
I want to print questions and respectiv answers , so I do a list and in that list I add a list
But it is not adding
There is my js code:
using UnityEngine;
using System;
using System.Data;
using System.Collections;
using MySql.Data.MySqlClient;
using System.Collections.Generic;
public class CSharp1 : MonoBehaviour
{
//This variable will be accessed through JavaScript
public string message = "And this is a C# code being accessed through JavaScript.";
private static MySqlConnection dbConnection;
public Texture backGround;
static string host = "127.0.0.1";
static string root = "root";
static string mdp = "";
static string result = "";
static int id = 0;
//public List<string> l = new List<string>();
public List<List<string>> Listquestion=new List<List<string>>();
//public List<string> list1 = new List<string>();
void OnGUI()
{Listquestion.Clear ();
Listquestion.Add (new List<String>());
string connectionString = "Server="+host+";Database=projet3d;User ID="+root+";Password="+mdp+";Pooling=false";
openSqlConnection(connectionString);
MySqlCommand mySqlCommand = new MySqlCommand("Select * from q_chap1 ;", dbConnection);
MySqlDataReader reader = mySqlCommand.ExecuteReader();
try
{
while (reader.Read())
{
if (reader.HasRows) {
Listquestion[id].Add (reader.GetString(1));
id=id+1;
Debug.Log("ok");
}
}id=0; }
catch (Exception)
{
Console.WriteLine("Failed!");
}
finally
{
reader.Close();
}
MySqlCommand mySqlCommand1 = new MySqlCommand("Select * from q_choix ;", dbConnection);
MySqlDataReader reader1 = mySqlCommand.ExecuteReader();
try
{
while (reader1.Read())
{
if (reader1.HasRows) {
Listquestion[id].Add (reader1.GetString(1));
Listquestion[id].Add (reader1.GetString(2));
Listquestion[id].Add (reader1.GetString(3));
Listquestion[id].Add (reader1.GetString(5));
id=id+1;
Debug.Log("ok");
}
}}
catch (Exception)
{
Console.WriteLine("Failed!");
}
finally
{
reader.Close();
}
closeSqlConnection(); }
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public static void OnApplicationQuit() {
closeSqlConnection();
}
// Connect to database
private static void openSqlConnection(string connectionString) {
dbConnection = new MySqlConnection(connectionString);
dbConnection.Open();
result = dbConnection.ServerVersion;
Debug.Log("Connected to database."+result);
}
// Disconnect from database
private static void closeSqlConnection() {
dbConnection.Close();
dbConnection = null;
//Debug.Log("Disconnected from database."+result);
}
// MySQL Query
public static void doQuery(string sqlQuery) {
IDbCommand dbCommand = dbConnection.CreateCommand();
dbCommand.CommandText = sqlQuery;
IDataReader reader = dbCommand.ExecuteReader();
reader.Close();
reader = null;
dbCommand.Dispose();
dbCommand = null;
}
}
Can you find my problemI checked many times but I cant finger out the problem
Thanks in advance