-1

我想使用 DataBindign 将图片添加到数据库中,但我不知道该怎么做。这是我用来加载图像的代码:

字节[] imgData;

 private void simpleButton5_Click_1(object sender, EventArgs e)
    {
        try
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                picture.ImageLocation = openFileDialog1.FileName;

                imgData = File.ReadAllBytes(openFileDialog1.FileName);
            }
        }
        catch (Exception ex)
        {
            // Could not load the image - probably related to Windows file system permissions.
            XtraMessageBox.Show("Cannot display the image.\n You may not have permission to read the file, or " +
                "it may be corrupt.\n\nReported error: " + ex.Message);
        }
    }
4

1 回答 1

0

这是您如何从数据库中读取 BLOB(在 Oracle 中)文件的代码。我希望它会对你有所帮助:

    private void ReadFileFromDatabase()
    {
        byte[] fileData = null;

        string selectSql = "SELECT FILE_DATA FROM BLOBTEST WHERE FILE_ID=1";

        OracleConnection con = new OracleConnection(conString);
        OracleCommand cmd = new OracleCommand(selectSql, con);

        try
        {
            con.Open();
            using (IDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    fileData = (byte[])reader["FILE_DATA"];
                    //do your operations with fileData here
                }
            }
        }
        finally
        {
            con.Close();
        }
    }
于 2012-07-30T04:50:24.190 回答