可能我没说清楚,我在我在SQL Server 2000中建了一个image类型的字段(photo)用来存储个人照片,做了一个存储过程,然后在类中的方法test加入一句
SqlComm.Parameters .Add ("@Photo",SqlDbType.Image ,16).Value=Photo;
其中SqlCommand SqlComm,@Photo在存储过程中定义为Image ,Byte Photo在winform内加了一个image控件,名为Picture,写入如下代码:
Photo=Convert.ToByte (Picture.Image.GetType () );其中Byte Photo,
但是我将Photo传入到类中的方法test中出错,是类型转换错误,请问该如何定义Photo类型,
编译时是通过的,但执行时就出错,各位帮我一把吧
SqlComm.Parameters .Add ("@Photo",SqlDbType.Image ,16).Value=Photo;
其中SqlCommand SqlComm,@Photo在存储过程中定义为Image ,Byte Photo在winform内加了一个image控件,名为Picture,写入如下代码:
Photo=Convert.ToByte (Picture.Image.GetType () );其中Byte Photo,
但是我将Photo传入到类中的方法test中出错,是类型转换错误,请问该如何定义Photo类型,
编译时是通过的,但执行时就出错,各位帮我一把吧
解决方案 »
- 关于DataTable往数据库中更新的问题!!
- submit和reset两个button都要运行js该怎么写
- 求一个完善的串口操作的类
- 如何创建文件后,并向文件中写入数据
- VS2010 using System.Runtime.InteropServices 无效
- 如何使用VS2003创建一个网站???
- Repeater控件绑定一张表,但这张表里面的字段名称是变量,数量也不固定,该怎样绑定?
- 如何将一个XML格式的数据载入到一个强类型的数据集(XSD)中?
- 大虾,小弟跪求关于treeview的一个问题.
- 关于Datagrid的问题,欢迎回答,越多越好,统统有分,在线等待.......
- c#里面连接数据库有几种方式?他们有怎样的优缺点
- 请SQL高手看看一个很有技术含量、但又简单的SQL查询语句,不胜感激!
{
//將數據表中的image讀取到picturebox
int nowPosition=this.BindingContext[this.dataset1,"customers"].Position ;
if (!(Convert.IsDBNull(this.dataset1.Tables["customers"].Rows[nowPosition] ["嘜頭"])))
{
// Open a stream for the image and write the bytes into it
byte[] byttrade=(byte[])this.dataset1.Tables["customers"].Rows[nowPosition]["嘜頭"];
System.IO.MemoryStream stmtrade=new MemoryStream(byttrade);
stmtrade.Write(byttrade,0,byttrade.Length);
// Create a bitmap from the stream
Bitmap bmp=new Bitmap(stmtrade);
// Check for scaling and assign the bitmap to the Picturebox
if (bmp.Width >264 && bmp.Height >184)
{
Bitmap bmp1=new Bitmap(bmp,new Size(264,184));
this.pictureBox1.Image=bmp1;
}
else
{this.pictureBox1.Image =bmp;}
}
else
{
this.pictureBox1.Image=null;
}
}
byte[] Data = new Byte[File.ContentLength];
//force the control to load data in array
File.InputStream.Read(Data,0,File.ContentLength);
//Create procedure parameter
object[] obj = new object[1]; obj[0] = Data;//Execute the procedure with Microsoft.ApplicationBlocks.Data
//Simple procedure
/*CREATE PROCEDURE sp_img(@img image) ASinsert into tb_img values(@img)*///record data
SqlHelper.ExecuteNonQuery(connectionString,"sp_img",obj);