什么语言,是VB还是其他的。我有VB的代码,不过今天肯定贴不上了。
解决方案 »
- 关于数据库的触发器问题
- 请教xmltype字段查询速度问题
- 请教一个关于oracle数据库备份导出的问题
- 怎么证明遵循两段锁协议的事务调度处理的结果是可串行化的?
- 系统崩溃怎么恢复Oracle数据库?
- 动态游标?问题!在线等待。。急。。。。。。。
- 为什么会这样?
- oracle中有一个表,让我用pl/sql误删除了,就是drop掉了,怎么样才能恢复阿
- ORACLE 方面高手注意了,我向你们提出挑战性的问题,此问题已经在多个论坛提出没有解决,不知....
- 2. 服务器上有三个在线重做日志组,每个组有两个成员,分布在不同的磁盘上,如果其中一个发现损害,启动时会出现什么情况?如何解决
- 如何用java调用oracle的存储过程(返回的是数据结果集)?
- 帮忙
1.首先有这个声明
Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
2。接下来就是两个函数了!
Public Function ImportPhoto(sPicFile As String, sEmpID As String) As String
If Trim(sPicFile) = "" Then Exit FunctionDim rcsPic As ADODB.Recordset
Dim sMax As String
Dim sInsertPic As String
'On Error GoTo ErrorImportPhotoDim rcsTemp As New Recordset
Dim sTempSQL As String Set rcsPic = New ADODB.Recordset
rcsPic.CursorType = adOpenKeyset
rcsPic.LockType = adLockOptimistic ' rcsPic.Open "T_PPICTURE ", AstDbCnt, , , adCmdTable Set mStream = New ADODB.Stream
mStream.Type = adTypeBinary
mStream.Open
mStream.LoadFromFile sPicFile'ÖØÐÂÌæ»»£¬Ê¹Óà pl/sql ʵÏÖ
rcsPic.AddNew
rcsPic.Fields("PERS").Value = sEmpID 'Ô±¹¤ ID
rcsPic.Fields("PIC").Value = mStream.Read
rcsPic.Update mStream.Close
Set mStream = Nothing
rcsPic.Close
Set rcsPic = Nothing
Exit Function
ErrorImportPhoto:
ImportPhoto = "FALSE"
End Function
Public Function DisplayPhoto(oPicture As PictureBox, sPicID As String)
Dim rcsDisplay As ADODB.Recordset
Set rcsDisplay = New ADODB.Recordset
Dim mStream As ADODB.Stream
Dim mc0 As String
rcsDisplay.Open "Select * from T_PPICTURE where PERS = '" & sPicID & "'", AstDbCnt, adOpenKeyset, adLockOptimistic If rcsDisplay.EOF Then
oPicture.Picture = LoadPicture()
Exit Function
End If
If IsNull(rcsDisplay.Fields("pic").Value) Then
oPicture.Picture = LoadPicture()
Exit Function
End If
Set mStream = New ADODB.Stream mStream.Type = adTypeBinary mStream.Open mStream.Write rcsDisplay.Fields("PIC").Value
strclose = App.Path & "\AstPhoto_temp"
DeleteFile (strclose)
mStream.SaveToFile strclose
mStream.Close
Set mStream = Nothing
rcsDisplay.Close
Set rcsDisplay = Nothing
oPicture.Picture = LoadPicture(strclose)
End Function应该可以直接调用了!
Sub AppendChunkByteExample(FName As String)'Declare various variables.Dim NumChunks As Integer, RemChunkSize As IntegerDim TotalSize As Long, CurChunkByte() As ByteDim I As Integer, FNum As Integer, ChunkSize As IntegerOn Error GoTo ERRORHANDLE 'Set the size of each chunk.
ChunkSize = 10240
frmChunk.MousePointer = HOURGLASS
'Begin an add operation.
'OraDynaset.AddNew
'Clear the LONGRAW field.
'OraDynaset.Fields("IMAGE").Value = ""
'Get a free file number.
FNum = FreeFile
'Open the file.
Open FName For Binary As #FNum
'Get the total size of the file.
TotalSize = LOF(FNum)
lblSize.Caption = CStr(TotalSize)
'Set number of chunks.
NumChunks = TotalSize / ChunkSize
'Set number of remaining bytes.
RemChunkSize = TotalSize Mod ChunkSize
OraDynaset.Edit
'Loop through the file.
For I = 0 To NumChunks
'Calculate the new chunk size.
If I = NumChunks Then
ChunkSize = RemChunkSize
End If
ReDim CurChunkByte(ChunkSize)
'Read a chunk from the file.
Get #FNum, , CurChunkByte
'Append chunk to LONGRAW field.
OraDynaset.Fields("IMAGE").AppendChunkByte CurChunkByte(0), ChunkSize
'OraField.AppendChunk (CurChunkByte)
Next I
'Complete the add operation and update the database.
OraDynaset.Update
'Close the file.
Close FNum
frmChunk.MousePointer = Default
Exit Sub
ERRORHANDLE:
MsgBox Err.Number & Err.DescriptionEnd Sub'db to file
Public Function GetChunkByteExample() As String
'Declare various variables
Dim CurSize As Long, ChunkSize As Long, TotalSize As Long
Dim I, J As Long
Dim CurChunk() As Byte, DestBlob() As ByteDim tempPath As String
Dim FileName As String
Dim FileNumber As IntegerOn Error GoTo ERRORHANDLE
If tempPath = "" Then
tempPath = GetWTempPath() + "FISCTemp\"
If Dir(tempPath, vbDirectory) = "" Then
MkDir (tempPath)
End If
FileName = GetTempName(tempPath)
End If
FileNumber = FreeFile()
Open FileName For Binary As FileNumber
'Set the size of each chunk
ChunkSize = 10240
'Redim CurChunk Array
ReDim CurChunk(ChunkSize)
frmChunk.MousePointer = HOURGLASS
'Refresh the dynaset.
OraDynaset.DbRefresh
' TotalSize = OraDynaset.Fields("IMAGE").FieldSize
' lblSize.Caption = CStr(TotalSize)
I = 0
'Loop through all of the chunks
'Oracle does not return the size of columns > 64KB.
'We should loop until the length of our block is
'less than we asked for.
Do
'Get chunk from long raw field
CurSize = OraDynaset.Fields("IMAGE").DbGetChunkByte(CurChunk(0), I * ChunkSize, ChunkSize) If CurSize < ChunkSize Then
ReDim CurChunk(CurSize)
CurSize = OraDynaset.Fields("IMAGE").DbGetChunkByte(CurChunk(0), I * ChunkSize, CurSize)
End If
TotalSize = TotalSize + CurSize
lblSize.Caption = CStr(TotalSize)
'Put chunk into buffer
' For J = 0 To CurSize - 1
' DestBlob(I * ChunkSize + J) = CurChunk(J)
' Next J
Put FileNumber, , CurChunk I = I + 1
Loop Until CurSize < ChunkSize
Close FileNumber
frmChunk.MousePointer = Default
GetChunkByteExample = FileName
Exit FunctionERRORHANDLE:
MsgBox Err.Number & Err.Description
End Function
'get temp path
Public Function GetWTempPath() As StringDim tStr As String tStr = Space(255)
Call GetTempPath(256, tStr)
tStr = Trim(tStr)
While (Right(tStr, 1) <> "\")
tStr = Left(tStr, Len(tStr) - 1)
Wend
GetWTempPath = tStr
End Function'get temp file
Public Function GetTempName(Optional tempPath As String, _
Optional FirstName As String = "", Optional LastName As String = "", _
Optional ExtendName As String = ".tmp") As String
Dim tName As String
Dim Upperbound As Long, Lowerbound As Long
Dim CFlag As Boolean If tempPath = "" Then
tempPath = GetWTempPath() + "FISCTemp\"
End If
Randomize
tName = ""
Upperbound = 2147483646
Lowerbound = 0
Do
tName = tempPath & FirstName & LastName & _
CLng((Upperbound - Lowerbound + 1) * Rnd + Lowerbound) _
& ExtendName
CFlag = True
If Dir(tName) <> "" Then
CFlag = False
Exit Do
End If
Loop While (Not CFlag)
GetTempName = tNameEnd Function
// 存数据到数据库中
//
SQLAllocStmt(hdbc,&hstmt);
retcode = SQLPrepare(hstmt, (BYTE *)"INSERT INTO TC13 VALUES(?,?,?,?)", SQL_NTS);
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
goto ERROR_EXIT; /* Bind the parameters. For parameter 2, pass */
/* the parameter number in ParameterValuePtr instead of a buffer */
/* address. */
//绑定文件编号
retcode=SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
SQL_C_ULONG, SQL_INTEGER,0, 0, &f_id, 0, &cbfid);
//绑定文件类型
retcode=SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT,
SQL_C_CHAR, SQL_VARCHAR,0, 0, &fileType, 0, &cbfileType);
//绑定文件信息,这个是参数化,以便将来传送数据
retcode=SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT,
SQL_C_ULONG, SQL_INTEGER,0, 0,(SQLPOINTER) 3, 0, &cbData);
//绑定文件长度
retcode=SQLBindParameter(hstmt, 4, SQL_PARAM_INPUT,
SQL_C_BINARY, SQL_LONGVARBINARY,
0, 0, &d_len, 0, &cbdlen);
//设置值以便在运行时向参数3传送数据
//SQL_DATA_LEN_AT_EXEC所使用的参数的长度为0
cbData = SQL_LEN_DATA_AT_EXEC(0);
//设置文件长度
d_len = size;
// d_id = 0;
retcode = SQLExecute(hstmt);
//如果要向参数发送数据
while(retcode == SQL_NEED_DATA)
{
retcode = SQLParamData(hstmt,&pToken);
if(retcode == SQL_NEED_DATA)
{
//如果文件没有结束
while(!feof(fp))
{
if((cbData=fread(Data,1,blocksize,fp))<0)
goto ERROR_EXIT; //如果读取文件出错
if(cbData==0)
break; //如果读出了0个数据
SQLPutData(hstmt,Data,cbData);//发送数据
}
}
}
/* while (retcode == SQL_SUCCESS && !feof(fp))
{
if((cbData=fread(Data,1,blocksize,fp))<0)
goto ERROR_EXIT;
if(cbData==0)
break;
d_len=cbData;
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
goto ERROR_EXIT;
d_id++;
}*/
SQLFreeStmt(hstmt,SQL_DROP);
fclose(fp);
delete []Data;
return TRUE;
ERROR_EXIT:
fclose(fp);
SQLFreeStmt(hstmt,SQL_DROP);
delete []Data;
return FALSE;
}