lundi 19 octobre 2015

C# Alter a BLOB field in Database

I've got a BLOB column in a sqlite databasefile an I want to alter this field to give it more information.

The BLOB contains this text:

"{\"Number\":\"35\",\"ChannelType\":\"TV\",\"ServiceName\":\"DVBLink\",\"ImageInfos\":[],\"IsInMixedFolder\":false,\"Name\":\"13th Street HD\",\"Id\":\"466ab1fb9be4f77e65ad2b229a15c326\",\"DateCreated\":\"2015-09-14T12:55:51.4081476Z\",\"DateModified\":\"0001-01-01T00:00:00.0000000Z\",\"DateLastSaved\":\"2015-10-17T13:34:37.4214116Z\",\"LockedFields\":[],\"ParentId\":\"00000000000000000000000000000000\",\"Studios\":[],\"Genres\":[],\"ProviderIds\":{\"ProviderExternalId\":\"13250000\"}}"

Here the code to get this information

        private void button1_Click(object sender, EventArgs e)
    {
        try {
            SQLiteConnection con = new SQLiteConnection("Data Source=D:\\2work\\VisualStudio\\Projects\\MapTVIcons\\library.db");

            con.Open();

            SQLiteCommand cmd = new SQLiteCommand();

            cmd.Connection = con;
            cmd.CommandText = "SELECT data FROM TypedBaseItems where type = 'MediaBrowser.Controller.LiveTv.LiveTvChannel'";
            //cmd.CommandText = "SELECT * FROM TypedBaseItems";

            DataSet ds = new DataSet();
            SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
            ds.Tables.Add("TypedBaseItems");
            da.Fill(ds);
            //dataGridView1.DataSource = ds.Tables[1];
           foreach (DataRow dr in ds.Tables[1].Rows)
            {


                byte[] array = (byte[])dr["data"];
                var str = System.Text.Encoding.Default.GetString(array);
            }
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }
}

What I want to do is readout the Id value and add a path to the "ImageInfos" and put the new BLOB back to the database file.

Aucun commentaire:

Enregistrer un commentaire