- Home /
Unity3d c# load or fill dataTable from sqLite local DataBase Error: sqlite3_column_Origin_name
hello everyone i use Unity 2018 for create android Game, so i use sqlite local Data base in my project. DataBase Address copy in 2 folder: 1) \Assets\youtube.bytes 2)`\Assets\StreamingAssets\youtube.bytes` my method to access to dataBase is:
string newDBPath = "";
if (Application.platform != RuntimePlatform.Android)
{
newDBPath = Application.dataPath + "/" + "youtube.bytes";
}
else
{
newDBPath = Application.persistentDataPath + "/" + "youtube.bytes";
if (!File.Exists(newDBPath))
{
WWW loadDB = new WWW("jar:file://" + Application.dataPath +
"!/assets/" + "youtube.bytes");
while (!loadDB.isDone) { }
File.WriteAllBytes(newDBPath, loadDB.bytes);
}
}
DataTable dataTable1 = new DataTable();
SqliteConnection con_db = new SqliteConnection("URI=file:" + newDBPath);
con_db.Open();
if (con_db.State == ConnectionState.Open)
{
SqliteCommand cmd_db = new SqliteCommand("Select * from Users", con_db);
SqliteDataReader rdr = cmd_db.ExecuteReader();
for fill DataTable:
dataTable1.Load(rdr);
for check i use this code:
if (dataTable1.Rows.Count > 0)
{
txtID.text = dataTable1.Rows[0][0].ToString().Trim();
}
but in Android Device return this Error: sqlite3_column_Origin_name ... Mono.Data.SqLite.sqLite3.ColumnOriginalName so i tried this:
SqliteDataAdapter da = new SqliteDataAdapter(sqlText, con_db);
da.Fill(dataTable1);
but return error Again, so i create manual Columns And Rows like :
if (rdr.HasRows)
{
dataTable1.Columns.Add(rdr.GetName(0), typeof(string));
dataTable1.Columns.Add(rdr.GetName(1), typeof(string));
dataTable1.Columns.Add(rdr.GetName(2), typeof(string));
while (rdr.Read())
{
dataTable1.Rows.Add(rdr[0].ToString(), rdr[1].ToString(), rdr[2].ToString());
}
}
its working fine, but some time i dont known how much Columns count in database Table, how many number is rdr.GetName (0), and it's not Pro method (sorry for my bad english).
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unity3d c# load or fill dataTable from sqLite local DataBase Error: sqlite3_column_Origin_name 0 Answers
Unity3d c# load or fill dataTable from sqLite local DataBase Error: sqlite3_column_Origin_name 0 Answers
Unity3d c# load or fill dataTable from sqLite local DataBase Error: sqlite3_column_Origin_name 0 Answers