如何将数据插入blob C#/ mysql / uwp

时间:2017-01-09 17:14:33

标签: c# mysql uwp

我正在尝试将PNG文件上传到mysql数据库blob类型列。

我到处搜索,这是我到目前为止所做的,但我被卡住了...... 我最终得到了数据库中的System.byte []。

public static byte[] ArtworkRawData

        StorageFile artworkfile = await openPicker.PickSingleFileAsync();
        if (artworkfile != null)
        {
            artworkSet = true;
            //var stream = await musicfile.OpenAsync(Windows.Storage.FileAccessMode.Read);
            artworkFileBTN.Content = artworkfile.DisplayName;
            var stream = await artworkfile.OpenAsync(FileAccessMode.Read);
            var streamBytes = await artworkfile.OpenStreamForReadAsync();
            var bytes = new byte[(int)streamBytes.Length];
            ArtworkRawData = bytes;
            var image = new BitmapImage();
            await image.SetSourceAsync(stream);
            artworkView.Source = image;
        }

我的查询如下:

if (DBC.Insert("INSERT INTO music(artwork) values('" +UploadMusicDialog.ArtworkRawData + "')")){

//do some stuff
}

更新

public bool Insert(string query)
    {
        //open connection
        if (OpenConnection() == true)
        {
            try
            {
                MySqlCommand cmd = new MySqlCommand(query, connection);
                cmd.ExecuteNonQuery();
                return true;

            }
            catch
            {
                return false;
            }
            finally
            {
                CloseConnection();
            }

        }else
        {

            return false;
        }
    }

0 个答案:

没有答案