如何用c#在sqlite数据库中添加图像

时间:2017-03-01 06:49:44

标签: c# database sqlite

我有一个sqlite数据库文件我想知道如何在WindowsFormsApplication中使用c#在数据库中添加图像。

我使用了以下代码,但它没有用,它说**

  

参数无效   system.drawing.imageconverter.fromstream(Stream stream,boolean use   EmbeddedColorManagement,Boolean ValidateImageData)

**

private void SelectAll_LockFolder_Button_Click(object sender, EventArgs e)
        {
            string filePath = @"I:\Locked.png";

            //A stream of bytes that represnts the binary file
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);

            //The reader reads the binary data from the file stream
            BinaryReader reader = new BinaryReader(fs);

            //Bytes from the binary reader stored in BlobValue array
            byte[] BlobValue = reader.ReadBytes((int)fs.Length);

            fs.Close();
            reader.Close();

            SQLiteConnection BlobsDatabaseConn = new SQLiteConnection(ConnectionString);
            SQLiteCommand SaveBlobeCommand = new SQLiteCommand();
            SaveBlobeCommand.Connection = BlobsDatabaseConn;
            SaveBlobeCommand.CommandType = CommandType.Text;


            string a = filePath.Substring(filePath.LastIndexOf("\\") + 1);

            SaveBlobeCommand.CommandText = "INSERT INTO Folders(FolderPath, Status) Values('" + a + "','" + BlobValue + "');";

            try
            {
                SaveBlobeCommand.Connection.Open();
                SaveBlobeCommand.ExecuteNonQuery();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Save Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            finally
            {
                SaveBlobeCommand.Connection.Close();
            }
        }

0 个答案:

没有答案