int与图像不兼容 [英] int is incompatible with image
本文介绍了int与图像不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我想将照片插入数据库...我使用数据类型图像作为照片栏
这是我用来插入数据库的代码.i
受保护 void Btn_Save_Click( object sender,EventArgs e)
{
objSqlData.SetSQLCommandParameterAddWithValue( @ Photo,SqlDbType.Image);
// 程序
}
这是我的存储过程
ALTER procedure Insert
as
开始
@ FirstName nvarchar ( 50 ),
@ LastName nvarchar ( 50 ),
@ Photo image
INSERT INTO 员工
(FirstName,LastName,photo)
VALUES ( @ FirstName , @ LastName , @ Photo )
end
谢谢
解决方案
// 获取上传文件的长度
int length = fileuploadImage.PostedFile.ContentLength;
// 创建一个字节数组来存储二进制图像数据
byte [] imgbyte = new byte [length] ;
// 将当前选定的文件存储在memeory中
HttpPostedFile img = fileuploadImage。 PostedFile;
// fileuploadImage是我的文件上传的名称
// 设置二进制数据
img.InputStream.Read(imgbyte, 0 ,长度);
// 请将图片转换为字节数组
cmd.Parameters.Add( @ Photo,SqlDbType.Image) .Value = imgbyte;
// cmd是sql命令类的对象
int count = cmd.ExecuteNonQuery();
// 此代码适用于asp.net
// 如果您在Windows应用程序中工作,请告诉我
Repace fileuploadImage,代码中包含fileuploder id;
如果它不适用于你
然后发布按钮内的所有代码单击。
这是一个窗口应用程序??
hello,
I want to insert photo into database...i have used datatype image for the photo column
this is the code i used to insert to databse..i
protected void Btn_Save_Click(object sender, EventArgs e)
{
objSqlData.SetSQLCommandParameterAddWithValue("@Photo", SqlDbType.Image);
// procedure
}
here is my stored procedure
ALTER procedure Insert
as
begin
@FirstName nvarchar(50),
@LastName nvarchar(50),
@Photo image
INSERT INTO Employee
(FirstName, LastName,photo)
VALUES (@FirstName , @LastName,@Photo)
end
Thank you
解决方案
//getting length of uploaded file int length = fileuploadImage.PostedFile.ContentLength; //create a byte array to store the binary image data byte[] imgbyte = new byte[length]; //store the currently selected file in memeory HttpPostedFile img = fileuploadImage.PostedFile; //fileuploadImage is the name of my file uploder //set the binary data img.InputStream.Read(imgbyte, 0, length); //please convert your image to byte array cmd.Parameters.Add("@Photo", SqlDbType.Image).Value = imgbyte; //cmd is a object of sql command class int count = cmd.ExecuteNonQuery(); //This code will work for asp.net //if u r working in windows application then let me know
Repace fileuploadImage with your fileuploder id in code;
If it is not working for u
then post all the code inside the button click.
is this a window application??
这篇关于int与图像不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文