当图像路径存储在数据库中时,如何在图像框中显示图像 [英] how to display image in an image box, when the image path is stored in the database

查看:62
本文介绍了当图像路径存储在数据库中时,如何在图像框中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到问题,在图像框中显示图像。我在桌子上有以下字段用户:

1用户名

2电子邮件 - 主键

3岁
4密码

5 image_name

6 image_path

以及保存图像的文件夹 - User_Pic。



现在,我使用以下代码保存了数据库中的图像名称和路径:

 FileUpload。 PostedFile.SaveAs(Server.MapPath( 〜/ User_Pic /)+ FileUpload.FileName.ToString( )); 
string Filename = Path.GetFileName(FileUpload.PostedFile.FileName);

string sql = 插入User_Table值(' + txtUser_Name.Text + ',' + txtEmail_Id.Text + ',' + txtAge.Text + ',' + txtPassword.Text + ',' +文件名+ ',' + User_Pic / +文件名+ ');

ob.cmd = new System.Data.SqlClient.SqlCommand(sql,ob.con);
ob.cmd.ExecuteNonQuery();
lblInfo.Text = 注册成功;



现在如何使用查询作为电子邮件ID在图像框中显示它:

  string  sql =  从User_Table中选择Image_Path,其中Email_Id =(' + TextBox1.Text +  '); 



after this i'我遇到了麻烦?



请帮助

解决方案

使用

 picturebox.ImageLocation =   your_image_path; 

并指定路径!


i''m having a problem, in displaying the image in the imagebox. i''m having the following fields in my table User:
1 user name
2 email- primary key
3 age
4 password
5 image_name
6 image_path
and the folder in which the image is saved named - User_Pic.

now, i have saved the image name and path in the database using the following code:

FileUpload.PostedFile.SaveAs(Server.MapPath("~/User_Pic/") + FileUpload.FileName.ToString());
string Filename = Path.GetFileName(FileUpload.PostedFile.FileName);

string sql = "insert into User_Table values('" + txtUser_Name.Text + "','" + txtEmail_Id.Text + "','" +  txtAge.Text + "','" + txtPassword.Text + "','" + Filename + "','" + "User_Pic/"+Filename + "')";

ob.cmd = new System.Data.SqlClient.SqlCommand(sql, ob.con);
ob.cmd.ExecuteNonQuery();
lblInfo.Text = "REGISTERED SUCCESSFULLY";


Now how to display it in image box using the query as email id:

string sql = "select Image_Path from User_Table where Email_Id = ('" + TextBox1.Text + "')";


after this i''m having the trouble ??

PLEASE HELP

解决方案

use

picturebox.ImageLocation="your_image_path";

and assign path to it!


这篇关于当图像路径存储在数据库中时,如何在图像框中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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