當前位置:首頁 » 編程語言 » sql照片怎麼導出來
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql照片怎麼導出來

發布時間: 2022-08-29 02:33:27

Ⅰ 如何從sql中導出照片

在MS SQL SERVER 安裝目錄下有個可執行文件叫 TEXTCOPY.EXE
可對 MS SQL SERVER 中的文本或圖像數據進行輸入輸出.
不過你可以在MS-DOS方式下執行text /? 得到它的描述。
下面是這個工具的描述:
Copies a single text or image value into or out of SQL Server. The val
ue
is a specified text or image 'column' of a single row (specified by th
e
"where clause") of the specified 'table'.

If the direction is IN (/I) then the data from the specified 'file' is

copied into SQL Server, replacing the existing text or image value. If
the
direction is OUT (/O) then the text or image value is copied from
SQL Server into the specified 'file', replacing any existing file.

TEXTCOPY [/S ][sqlserver]] [/U [login]] [/P ][password]]
[/D ][database]] [/T table] [/C column] [/W"where clause"]
[/F file] [{/I | /O}] [/K chunksize] [/Z] [/?]

/S sqlserver The SQL Server to connect to. If 'sqlserver' is n
ot
specified, the local SQL Server is used.
/U login The login to connect with. If 'login' is not spec
ified,
a trusted connection will be used.
/P password The password for 'login'. If 'password' is not
specified, a NULL password will be used.
/D database The database that contains the table with the tex
t or
image data. If 'database' is not specified, the d
efault
database of 'login' is used.
/T table The table that contains the text or image value.

/C column The text or image column of 'table'.
/W "where clause" A complete where clause (including the WHERE keyw
ord)
that specifies a single row of 'table'.
/F file The file name.
/I Copy text or image value into SQL Server from 'fi
le'.
/O Copy text or image value out of SQL Server into '
file'.
/K chunksize Size of the data transfer buffer in bytes. Minimu
m
value is 1024 bytes, default value is 4096 bytes.

/Z Display debug information while running.
/? Display this usage information and exit.

You will be prompted for any required options you did not specify.

為此, 可寫一個存儲過程,調用這個命令
CREATE PROCEDURE sp_text (
@srvname varchar (30),
@login varchar (30),
@password varchar (30),
@dbname varchar (30),
@tbname varchar (30),
@colname varchar (30),
@filename varchar (30),
@whereclause varchar (40),
@direction char(1))
AS
DECLARE @exec_str varchar (255)
SELECT @exec_str =
'text /S ' + @srvname +
' /U ' + @login +
' /P ' + @password +
' /D ' + @dbname +
' /T ' + @tbname +
' /C ' + @colname +
' /W "' + @whereclause +
'" /F ' + @filename +
' /' + @direction
EXEC master..xp_cmdshell @exec_str

下面是一個拷貝圖像到SQL Server的pubs資料庫的例子, 表名pub_info, 欄位名
logo,圖像文件名picture.bmp,保存到pub_id='0736'記錄 sp_text @srvn
ame = 'ServerName',
@login = 'Login',
@password = 'Password',
@dbname = 'pubs',
@tbname = 'pub_info',
@colname = 'logo',
@filename = 'c:\picture.bmp',
@whereclause = " WHERE pub_id='0736' ",
@direction = 'I'
你看看 調用成拷貝就行

Ⅱ 怎樣把SQL資料庫里的圖片導出到指定的文件夾

首先可以還原或附加這個資料庫的備份,然後就找到存放圖片的欄位讀出來,
通過。net、java等語言編程的程序讀出這個欄位的數據保存到文件夾就OK了.

Ⅲ 導出sql2005 資料庫中的jpg格式圖片導出

使用asp代碼導出,資料庫中的二進制圖片導出為本地JPG圖片
此方法可以把以二進制存儲在資料庫中的圖片通過ADODB.Stream以圖片格式保存到電腦硬碟中,非常實用且精典,值得收藏!
<%
db="img.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
conn.Open connstr
set rs=server.createobject("ADODB.recordset")
sql="select * from img"
rs.open sql,conn,1,1
do while not rs.eof
call SaveToFile(rs("pic"),rs("id")&".gif")
rs.movenext
loop
rs.close
set rs=nothing
set conn=nothing

Sub SaveToFile(ByVal strBody,ByVal Filename)
'***********************
'存儲內容到文件
'by 天涯才 QQ:23969
'[email protected]
'2005-08-11
'winXP+IIS5.5測試通過
'***********************
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
If Err.Number=-2147221005 Then
Response.Write "<div align='center'>非常遺憾,您的主機不支持ADODB.Stream,不能使用本程序</div>"
Err.Clear
Response.End
End If
With objStream
.Type = 2
.Open
.Position = objStream.Size
.WriteText = strBody
.SaveToFile Server.MapPath(Filename),2
.Close
End With
Set objStream = Nothing
End Sub
%>

注意:後來用PS打不開,報錯。而且用IE也不識別。
解決的辦法:用ACDSee 打開,選中圖片右鍵=>轉換=>在框內選擇JPG格式=>確定即可!

Ⅳ 導出sql照片

ASP

此方法可以把以二進制存儲在資料庫中的圖片通過ADODB.Stream以圖片格式保存到電腦硬碟中,非常實用且精典,值得收藏!

<%
db="img.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
conn.Open connstr
set rs=server.createobject("ADODB.recordset")
sql="select * from img"
rs.open sql,conn,1,1
do while not rs.eof
call SaveToFile(rs("pic"),rs("id")&".gif")
rs.movenext
loop
rs.close
set rs=nothing
set conn=nothing

Sub SaveToFile(ByVal strBody,ByVal Filename)
'***********************
'存儲內容到文件

'winXP+IIS5.5測試通過
'***********************
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
If Err.Number=-2147221005 Then
Response.Write "<div align='center'>非常遺憾,您的主機不支持ADODB.Stream,不能使用本程序</div>"
Err.Clear
Response.End
End If
With objStream
.Type = 2
.Open
.Position = objStream.Size
.WriteText = strBody
.SaveToFile Server.MapPath(Filename),2
.Close
End With
Set objStream = Nothing
End Sub
%>

注意:後來用PS打不開,報錯。

而且用IE也不識別。

解決的辦法:

用ACDSee 打開,選中圖片右鍵=>轉換=>在框內選擇JPG格式=>確定即可!

Ⅳ SQL導出圖片問題

Dim conn As SqlConnection = New SqlConnection
conn.ConnectionString = "data source=your ip address,port; network library=dbmssocn; initial catalog=your database name;password=your password; user id=your user id;"
conn.Open()
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = "select id, imagedata from yourTableName"
cmd.CommandType = CommandType.Text
cmd.Connection = conn
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()
Dim b As Byte()
Dim id As Integer
Dim filename As String = "d:\{0}.jpg"
While dr.Read()
id = dr.Item("id").ToString()
b = dr.Item("imagedata")
Dim stream As New System.IO.MemoryStream
Dim image As System.Drawing.Image
stream.Write(b, 0, b.Length)
image = System.Drawing.Image.FromStream(stream)
image.Save(String.Format(filename, id))
End While
dr.Close()
conn.Close()

Ⅵ 如何sql語句把sql2005中的圖片導出,請高手幫幫忙寫個SQL語句。表名hr_hi_person,圖片欄位mpicture 。

圖片存放的資料庫是二進制的。通過SQL無法導出成圖片。需要在程序裡面轉換。
resultset rs=con.openresult(" select mpicture fromm hr_hi_person");
while(rs.next){
image a=image.frombyte(rs.getstring(1).getbytes());

}

大概是這樣,記得不是很清楚

Ⅶ 怎麼把sql數據中的二進制圖片批量導出到本地啊,有木有工具,求大神發個來郵箱:[email protected]

一般情況下,圖片是以文件的形式保存在計算機上而非資料庫的表欄位中,資料庫只是保存了該文件的索引,所以,你可以直接登錄伺服器將文件復制回來。

Ⅷ 怎麼樣批量導出sql資料庫中的圖片

  1. 打開資料庫SQL server ,右擊資料庫選擇「任務」 「生成腳本

  2. 選擇你要導出的資料庫,點擊下一步

  3. 將編寫數據腳本選項選擇為true,點擊下一步

  4. 選擇表,點擊下一步

  5. 選擇你要導出表的數據

  6. 選擇將腳本保存到「新建查詢」窗口,點擊下一步,

  7. 點擊完成,之後就不要操作,直到生成腳本成功後,點擊關閉按鈕。

  8. 只要在其他資料庫中直接運行,同樣的一張表就在另一個資料庫中生成了。

Ⅸ 求助:如何將SQL裡面的image欄位導出到EXCEL顯示為圖片

image列以二進制的形式存儲的,sql不能實現直接顯示在EXCEL中,一般要通過程序開發語言在前端實現;
但可以考慮以html格式保存,這樣image上傳到了伺服器端,這樣直接復制到excel是可以顯示html頁面的。