-
Notifications
You must be signed in to change notification settings - Fork 10
/
sdb.cs
92 lines (83 loc) · 3.05 KB
/
sdb.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mono.Data.Sqlite;
using System.Data;
using System;
public class insert : MonoBehaviour {
private string conn, sqlQuery;
IDbConnection dbconn;
IDbCommand dbcmd;
// Use this for initialization
void Start () {
conn = "URI=file:" + Application.dataPath + "/Plugins/Users.s3db"; //Path to database.
//Deletvalue(6);
//insertvalue("ahmedm", "[email protected]", "sss");
Updatevalue("a","[email protected]","1st",1);
readers();
}
private void insertvalue(string name, string email, string address)
{
using (dbconn = new SqliteConnection(conn))
{
dbconn.Open(); //Open connection to the database.
dbcmd = dbconn.CreateCommand();
sqlQuery = string.Format("insert into Usersinfo (Name, Email, Address) values (\"{0}\",\"{1}\",\"{2}\")",name,email,address);// table name
dbcmd.CommandText = sqlQuery;
dbcmd.ExecuteScalar();
dbconn.Close();
}
}
private void Deletvalue(int id)
{
using (dbconn = new SqliteConnection(conn))
{
dbconn.Open(); //Open connection to the database.
dbcmd = dbconn.CreateCommand();
sqlQuery = string.Format("Delete from Usersinfo WHERE ID=\"{0}\"", id);// table name
dbcmd.CommandText = sqlQuery;
dbcmd.ExecuteScalar();
dbconn.Close();
}
}
private void Updatevalue(string name, string email, string address,int id)
{
using (dbconn = new SqliteConnection(conn))
{
dbconn.Open(); //Open connection to the database.
dbcmd = dbconn.CreateCommand();
sqlQuery = string.Format("UPDATE Usersinfo set Name=\"{0}\", Email=\"{1}\", Address=\"{2}\" WHERE ID=\"{3}\" ", name, email, address, id);// table name
dbcmd.CommandText = sqlQuery;
dbcmd.ExecuteScalar();
dbconn.Close();
}
}
private void readers()
{
using (dbconn = new SqliteConnection(conn))
{
dbconn.Open(); //Open connection to the database.
dbcmd = dbconn.CreateCommand();
sqlQuery = "SELECT * " + "FROM Usersinfo";// table name
dbcmd.CommandText = sqlQuery;
IDataReader reader = dbcmd.ExecuteReader();
while (reader.Read())
{
int id = reader.GetInt32(0);
string name = reader.GetString(1);
string Email = reader.GetString(2);
string Phone = reader.GetString(3);
Debug.Log("value= " + id + " name =" + name + " Eamil =" + Email + " Phone" + Phone);
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbconn.Close();
dbconn = null;
}
}
// Update is called once per frame
void Update () {
}
}