从数据库中检索图像时的参数无效 [英] Invalid parameter when retrieving image from DB

查看:244
本文介绍了从数据库中检索图像时的参数无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最后,我想抓住从Access数据库的OLE类型的图像,并把它变成一个图片框。在C#和Visual Studio 2012的工作和MS Access 2010中我的解决方案是一个应用程序的非Web相关的。



所以这是查询代码。我构造一个对象( Equipamento )与为重点的为System.Drawing.Image 属性等等。问题

  OleDbConnection的L = OleDbConnectionDAO.createConnection(); 
Equipamento EQ =新Equipamento();


{
OleDbDataAdapter的适配器=新OleDbDataAdapter的(
SELECT * FROM [APP_Equipamento_Geral]其中COD_ETIQ LIKE'%
+ codigo
+%',
L);
的DataSet DS =新的DataSet();
adapter.Fill(DS,[APP_Equipamento_Geral]);
字符串s = ds.Tables [[APP_Equipamento_Geral]]列[16] .ColumnName;
的foreach(DataRow的行ds.Tables [[APP_Equipamento_Geral]]行。)
{
eq.NInventario =行[Codigo]的ToString()。
eq.Modelo =行[MODELO]的ToString()。
eq.Marca =行[马卡报_]的ToString()。
eq.GamaMedida =行[伽马Medida]的ToString()。

如果(行[FOTO] = DBNull.Value和放大器;!&安培;!行[FOTO] = NULL)
{
的byte [] B =新字节[0];
B =(字节[])行[FOTO];

eq.Img = getImageFromBytes(B); //错误这里抓到
}


//如果(行[FOTO]! = DBNull.Value和放大器;&安培;!行[FOTO] = NULL)
// {
//字节[] b =(字节[])行[FOTO];
//的MemoryStream毫秒=新的MemoryStream(B);
// eq.Img = Image.FromStream(毫秒); //这里抓到错误
//}
}
}

这里是辅助方法:

 专用图像getImageFromBytes(字节[] myByteArray)
{
System.IO.MemoryStream newImageStream
=新System.IO.MemoryStream(myByteArray,0,myByteArray.Length); \

返回Image.FromStream(newImageStream,真);
}

这是代码的最后评论的作品是我的另一个尝试也给了<的/ p>


无效的参数




错误。 ?任何解决方案



请注意:如果我拿出图像部分的一切工作正常。


解决方案<。 / DIV>

存储为 OLE对象的图像具有从序列化不同的格式为System.Drawing.Image 。这就是为什么我问的图像存储方式。



虽然我不能保证这一点,从来没有亲自使用过,多是建议使用下面的代码。据称,它采用了GDI + lib目录从MS(包括在赢标准安装)来导入/导出图片到/从访问OLE



http://www.access-im-unternehmen.de/index1.php?BeitragID=337& ; ID = 300



您可以找到其他建议(包括实用工具从访问您的图片),在此链接:



转换MS访问" OLE对象和QUOT;回到普通JPEG文件 - ?最好的办法


In the end I want to grab a OLE type image from an Access Database and put it into a picture box. Working with Visual Studio 2012 in C# and MS Access 2010. My solution is an app non-web related.

So this is the query code. I'm constructing an object (Equipamento) with among others an System.Drawing.Image attribute that is the focus of the issue.

OleDbConnection l = OleDbConnectionDAO.createConnection();
Equipamento eq = new Equipamento();

try
{
    OleDbDataAdapter adapter = new OleDbDataAdapter(
        "SELECT * FROM [APP_Equipamento_Geral] WHERE COD_ETIQ like '%"
           + codigo
           + " %'",
        l);
    DataSet ds = new DataSet();
    adapter.Fill(ds, "[APP_Equipamento_Geral]");
    string s = ds.Tables["[APP_Equipamento_Geral]"].Columns[16].ColumnName;
    foreach (DataRow row in ds.Tables["[APP_Equipamento_Geral]"].Rows)
    {                
        eq.NInventario = row["Codigo"].ToString();
        eq.Modelo = row["MODELO"].ToString();
        eq.Marca = row["Marca_"].ToString();
        eq.GamaMedida = row["Gama Medida"].ToString();

        if (row["FOTO"] != DBNull.Value && row["FOTO"] != null)
        {
            byte[] b = new byte[0];
            b = (byte[])row["FOTO"];

            eq.Img = getImageFromBytes(b);//Error caught here
        } 


        //if (row["FOTO"] != DBNull.Value && row["FOTO"] != null)
        //{
        //    byte[] b = (byte[])row["FOTO"];
        //    MemoryStream ms = new MemoryStream(b);
        //    eq.Img = Image.FromStream(ms);  //Error caught here
        //} 
    }
}

And here is the auxiliary method:

private Image getImageFromBytes(byte[] myByteArray)
{
    System.IO.MemoryStream newImageStream
        = new System.IO.MemoryStream(myByteArray, 0, myByteArray.Length);\

    return Image.FromStream(newImageStream, true);
}

That last commented piece of code was another of my attempts that also gave the

Invalid parameter

error. Any solutions?

Note: If I take out the image part everything works fine.

解决方案

An image stored as an OLE object has a different format from a serialized System.Drawing.Image. That's why I asked how the images were stored.

While I cannot vouch for this, never having used it personally, the following code is much recommended. Supposedly, it uses the GDI+ lib from MS (included in Win standard installation) to import/export pics to/from Access OLE.

http://www.access-im-unternehmen.de/index1.php?BeitragID=337&id=300

You can find other suggestions (including a utility to extract your images from Access) at this link:

Converting MS Access "OLE Objects" back to plain JPEGs - best way?

这篇关于从数据库中检索图像时的参数无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆