Пример #1
0
 // データを更新するする
 public void UpdateData(TAHLocalDBDataEntry entry)
 {
     using (SQLiteCommand cmd = cnn.CreateCommand())
     {
         cmd.CommandText = "UPDATE Data SET DATA=@data WHERE DATAID=@id";
         cmd.Parameters.AddWithValue("id", entry.dataid.ToString());
         cmd.Parameters.AddWithValue("data", entry.data);
         cmd.ExecuteNonQuery();
     }
 }
Пример #2
0
        //                    cmd.CommandText = "CREATE TABLE Data (DATAID PRIMARY KEY, DATA BLOB)";

        // データを取得する
        public TAHLocalDBDataEntry GetData(int id)
        {
            TAHLocalDBDataEntry entry = null;

            using (SQLiteCommand cmd = cnn.CreateCommand())
            {
                cmd.CommandText = "SELECT DATAID,DATA FROM Data WHERE DATAID=@id";
                cmd.Parameters.AddWithValue("id", id.ToString());
                using (SQLiteDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        entry        = new TAHLocalDBDataEntry();
                        entry.dataid = int.Parse(reader[0].ToString());
                        entry.data   = (byte[])reader[1];
                        break;
                    }
                }
            }
            return(entry);
        }
Пример #3
0
        public int AddData(TAHLocalDBDataEntry entry)
        {
            int id = -1;

            using (SQLiteCommand cmd = cnn.CreateCommand())
            {
                // acpathを追加する.
                cmd.CommandText = "INSERT INTO Data (DATA) VALUES(@data)";
                cmd.Parameters.AddWithValue("data", entry.data);
                cmd.ExecuteNonQuery();

                cmd.CommandText = "SELECT last_insert_rowid()";
                using (SQLiteDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        id = Int16.Parse(reader[0].ToString());
                        break;
                    }
                }
            }
            return(id);
        }