2014-10-01 73 views
0

我有我轉換成字節的PDF文件,但它說:節約斑點用Visual Basic

There was an error: Invalid data type 

我不知道如果我做錯了,它可能保存PDF這條路? 我的數據庫是這樣的

CREATE TABLE emision_modificacion_eliminacion(
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, 
file_name VARCHAR(64) NOT NULL, 
file_size MEDIUMINT UNSIGNED NOT NULL, 
file MEDIUMBLOB NOT NULL); 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)    Handles Button2.Click 
    Dim fs As FileStream 
    Dim FileSize As UInt32 
    Dim rawData() As Byte 
    Dim cmd As New MySQLCommand 
    Try 
     fs = New FileStream("C:\Objetivos.pdf", FileMode.Open, FileAccess.Read)    
     FileSize = fs.Length 
     rawData = New Byte(FileSize) {} 
     fs.Read(rawData, 0, FileSize) 
     fs.Close() 
     cmd = conxv.crear_consulta(cnn, "INSERT INTO emision_modificacion_eliminacion VALUES(NULL,'Objetivos.pdf', ?FileSize,?File)") 
     cmd.Parameters.Add("?FileSize", FileSize) 
     cmd.Parameters.Add("?File", rawData) 
     cmd.ExecuteNonQuery() 
     MessageBox.Show("File Inserted into database successfully!", _ 
     "Success!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk) 
     cnn.Close() 
    Catch ex As Exception 
     MessageBox.Show("There was an error: " & ex.Message, "Error", _ 
      MessageBoxButtons.OK, MessageBoxIcon.Error) 
     cnn.Close() 
    End Try 
End Sub 

回答

0

你確定這是BLOB導致你麻煩嗎?

你不應該需要通過對AUTO_INCREMENT類型的東西,所以我會改寫這樣的SQL:

"INSERT INTO emision_modificacion_eliminacion VALUES('Objetivos.pdf', ?FileSize, ?File)" 

這可能是導致錯誤的null

+0

是的,我要在這裏嘗試另一種轉換 – user3215218 2014-10-02 15:10:21