本文介绍了如何在数据库中添加图像的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有sql代码将图像从我的系统插入数据库。在此代码中,文件名不会打印。如何打印文件名? CREATE TABLE [dbo]。[图片]( [id] [ int ] IDENTITY ( 1 , 1 ) NOT NULL , [文件名] varchar ( 100 ), [路径] varchar ( 200 ), [document] [ image ] NULL ) DECLARE @ imgString varchar ( 80 ), @ imgNumber int DECLARE @ insertString varchar ( 3000 ) SET @ imgNumber = 13 WHILE ( @ imgNumber < 19 ) BEGIN SET @ imgString = ' D:\ images \ 43 - ' + CONVERT ( varchar , @ imgNumber )+ ' 。jpg' SET @ insertString = N ' INSERT INTO Images(document) SELECT * FROM OPENROWSET(BULK N''' + @ imgString + ' '',SINGLE_BLOB)as tempImg' EXEC ( @ insertString ) SET @ imgNumber = @ imgNumber + 1 EXEC ( @insertString ) END 选择 * 来自图片 也适用于非出现在系统中它显示错误解决方案 请尝试以下链接。 http://www.aspsnippets.com/Articles/Retrieve- images-using-a-file-path-stored-in-database-in-ASPNet.aspx [ ^ ] http://www.aspdotnet-suresh.com/2011/03/how-to-save-images-into-folder-and.html [ ^ ] 在 INSERT 语句中,您只定义了文档领域。因此,所有其他字段都留空,因此它们获得默认值。 尝试将插入更改为类似 SET @ insertString = N ' INSERT INTO Images(文件名,路径,文档)... 只要确保你在 SELECT 部分中提供相应的值 不要在您的应用中使用图像数据类型。 在使用数据类型之前是SQL Server,请阅读 - > 点击此处 I have sql code to insert images from my system to the database. In this code the file name is not printing. How can I print the file name?CREATE TABLE [dbo].[Images]( [id] [int] IDENTITY(1,1) NOT NULL, [Filename] varchar(100), [Path] varchar(200), [document] [image] NULL )DECLARE @imgString varchar(80), @imgNumber intDECLARE @insertString varchar(3000)SET @imgNumber = 13WHILE (@imgNumber < 19)BEGIN SET @imgString = 'D:\images\43-' + CONVERT(varchar,@imgNumber) + '.jpg' SET @insertString = N'INSERT INTO Images(document) SELECT * FROM OPENROWSET(BULK N''' + @imgString + ''', SINGLE_BLOB) as tempImg' EXEC(@insertString) SET @imgNumber = @imgNumber + 1 EXEC(@insertString)ENDselect * from imagesalso for images that are not present in system it shows error 解决方案 Try this link below.http://www.aspsnippets.com/Articles/Retrieve-images-using-a-file-path-stored-in-database-in-ASPNet.aspx[^]http://www.aspdotnet-suresh.com/2011/03/how-to-save-images-into-folder-and.html[^]In your INSERT statement you're only defining the document field. Because of this all other fields are left empty so they get their default values.Try changing your insert to something likeSET @insertString = N'INSERT INTO Images(filename, path, document)...Just make sure that you provide corresponding values in the SELECT portiondon't use Image Data-type in your apps.before using data types is SQL Server, read this on -> Click Here 这篇关于如何在数据库中添加图像的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!