将图像从我的网格上传到sql server [英] uploading an image from my grid to sql server

查看:72
本文介绍了将图像从我的网格上传到sql server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:)

我的项目有问题:\

我有这张桌子:

用户:
-User_ID
-User_Name
.
.
.
-User_Avatar

我将用户图像保存在〜/Pic"/users"之类的文件夹中

并且我有一个由向导限制到此表的网格,带有插入和更新选项

当我尝试更新或插入新行时,没有数据保存到我的数据库中

如何将图像上传到用户的图片文件夹,并将其名称保存到User_Avatar列?

如果在编辑和插入模式下将图像字段转换为上载控件,是否有任何问题?

请帮助我解决这个问题

谢谢大家:)

Hi all :)

I have a problem with my project :\

I have this table:

Users:
-User_ID
-User_Name
.
.
.
-User_Avatar

I save users images at a folder like "~/Pic''s/users"

and I have a grid bounded to this table by wizard, with insert and update options

put when i try to update or insert a new row, no data saved to my data base

how can i upload images to users'' pictures folder, and save its name to User_Avatar column ?

and is there any problem if I convert image field to upload control in edit and insert mode ?

please help me with this problem

thank you all :)

推荐答案

尝试一下
if (FileUpload1.HasFile)
{
  Int64 intFileSize = Convert.ToInt64(FileUpload1.PostedFile.ContentLength);
  if (intFileSize > 3145728)
  {
   spnErrorLogo.InnerHtml = " Please upload a file less than 3 MB in size.";  
   return;
  }
 string Name = FileUpload1.FileName.Replace(" ", "");
string CompletePath = "UploadPatientImage/" + PID + "/PatientImage/" + Name;
string TempPath = "UploadPatientImage\\TempImage";
DirectoryInfo thisFolder = new DirectoryInfo(TempPath);
if (!thisFolder.Exists)
{
thisFolder.Create();
}
FileUpload1.PostedFile.SaveAs(TempPath + "\\" + imgNewName);
ClsPatient objP = objPDb.InsertPatientPicture(PID, CompletePath);
}


我认为您应该执行以下操作:

1.在网格的编辑和插入模式下具有fileUploader控件.
注意(您无法在FileUploader控件中设置数据,只能从中获取数据.)
2.将上载的文件保存在上面指定的路径中,然后仅将该文件的路径保存在数据库中.
3.在绑定过程中,从您在步骤2中保存的数据库中获取图片的路径,并将该路径绑定到任何图像控件的src或imageUrl属性.
我想这应该可以满足您的需求.
快乐的编码:)
I think you should the following :

1. Have a fileUploader control in edit and insert mode of the grid.
NOTE (You can''t set the data in the FileUploader control, you can only get the data from it.)
2. Save the uploaded file at the path you specified above and save only path of that file in your database.
3. During binding fetch the pic''s path from the database which you have saved in step 2 and bind that path to any image control''s src or imageUrl property.

I guess this should do what you need.
happy coding :)


这篇关于将图像从我的网格上传到sql server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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