· 7 years ago · Feb 25, 2019, 10:04 PM
1public void getDropDown () {
2
3 string conn = "URI=file:" + Application.dataPath + "/Plugins/" + namedb;
4 IDbConnection dbconn;
5 dbconn = (IDbConnection)new SqliteConnection (conn);
6 dbconn.Open ();
7 IDbCommand dbcmd = dbconn.CreateCommand ();
8 //Creamos la tabla de los usuarios.
9 string creacion = "CREATE TABLE IF NOT EXISTS usuarioData (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, names TEXT NOT NULL )";
10
11 dbcmd.CommandText = creacion;
12 dbcmd.ExecuteNonQuery ();
13
14 string sqlQuery = "Select * From usuarioData";
15 dbcmd.CommandText = sqlQuery;
16 IDataReader reader = dbcmd.ExecuteReader ();
17 while(reader.Read()){
18 nombres.Add(reader.GetString (1));
19 //Debug.Log ("ID"+ id +" Nombre"+ names);
20 }
21
22 dropdown.AddOptions(nombres);
23
24 reader.Close ();
25 reader = null;
26 dbcmd.Dispose ();
27 dbcmd = null;
28 dbconn.Close ();
29 dbconn = null;
30
31}
32
33public void insertDb(){
34
35 string inputText = names.text;
36 string conn = "URI=file:" + Application.dataPath + "/Plugins/"+namedb ;
37 IDbConnection dbconn;
38 dbconn = (IDbConnection)new SqliteConnection (conn);
39 dbconn.Open ();
40 IDbCommand dbcmd = dbconn.CreateCommand ();
41 string sqlQuery = "INSERT INTO usuarioData (names) VALUES ('" + inputText + "')";
42 dbcmd.CommandText = sqlQuery;
43 dbcmd.ExecuteReader ();
44
45 dbcmd.Dispose ();
46 dbcmd = null;
47 dbconn.Close ();
48 dbconn = null;
49
50 mText.text = "El nombre: " + inputText + " Ha sido guardado";
51
52}