如何在数据库中存储文件名 [英] How stored filename in database

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

问题描述

这是我用于在数据库中保存图像和图像名称的代码

This is my code for save image and image name in database

OpenFileDialog fop = new OpenFileDialog();
//fop.InitialDirectory = @"C:\Users\ODYSSEY\Downloads\Documents\Panorama\Resources\";
fop.Filter = "[JPG,JPEG]|*.jpg";
if (fop.ShowDialog() == DialogResult.OK)
{
  FileStream FS = new FileStream(@fop.FileName, FileMode.Open, FileAccess.Read);
  byte[] img = new byte[FS.Length];
  FS.Read(img, 0, Convert.ToInt32(FS.Length));
  if (con.State == ConnectionState.Closed)
    con.Open();
  SqlCommand cmd = new SqlCommand("SaveImage", con);
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.Parameters.Add("@img", SqlDbType.Image).Value = img;
  cmd.Parameters.Add("@imgname", SqlDbType.VarChar).Value = @fop.FileName;
  cmd.ExecuteNonQuery();


它将图像存储为二进制数据,将imageName存储为完整路径,例如c:\ Documents \ Images \ Rose.jpgi>我要在数据库中将imageName保存为"Rose.jpg".我该怎么做?


It store image as binary data and imageName as full path for example c:\Documents\Images\Rose.jpgi>I want to save imageName as "Rose.jpg" in database. How can i do this?

推荐答案

使用
Use Path.GetFilename()[^].

/ravi


此处 [ ^ ],您将找到答案; )
Here[^] you''ll find your answer ;)


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

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