[.NET] BLOB傳MySQL資料庫
請輸入專案類型(網站專案或者應用程式專案):應用程式專案
這幾天參考了很多範例
但大部分都是vb2005 + sql server的寫法
總之拼拼湊湊vb2005 + mysql5 一般的資料也是可以進去了
但BLOB的資料怎麼樣都進不去
換了很多種方法也都是在"addEmp.ExecuteNonQuery()"錯誤
煩請各位先進能提供些解決辦法嗎?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim myConnectionString As String
Dim asc() As Byte = Getasc(Application.StartupPath & _
"\Images\CEH_20020304000000.asc")
myConnectionString = "server=xxx.xxx.xxx.xxx;" _
& "uid=xxxx;" _
& "pwd=xxxx;" _
& "database=test;"
Try
Dim conn As New MySql.Data.MySqlClient.MySqlConnection(myConnectionString)
conn.Open()
Catch ex As MySql.Data.MySqlClient.MySqlException
Select Case ex.Number
Case 0
MsgBox("Cannot connect to server. Contact administrator")
Case 1045
MsgBox("Invalid username/password, please try again")
End Select
End Try
'-------------------------------------------------------------------
Dim myConnection As New MySqlClient.MySqlConnection(myConnectionString)
Dim addEmp As MySqlClient.MySqlCommand = New MySqlClient.MySqlCommand("INSERT INTO test (date, value)" &
"Values(20080904120000,@asc)", myConnection)
addEmp.Parameters.Add("@asc", SqlDbType.Binary, Int(asc.Length)).Value = asc
myConnection.Open()
addEmp.ExecuteNonQuery()
myConnection.Close()
End Sub
Public Shared Function Getasc(ByVal filePath As String) As Byte()
Dim fs As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
Dim br As BinaryReader = New BinaryReader(fs)
Dim asc() As Byte = br.ReadBytes(fs.Length)
br.Close()
fs.Close()
Return asc
End Function
--
╱ ▅ ███▆ ◥█◥◥█ ▇▇▂███◤▄ ╲
╱ 做研究的人們啊 ▅ ◥█___▍ ◥ ◥▌ ████◤▅分一點章節給 ╲
╱ ╱ ▄◥ ██◤▃▅ 想要畢業的我
╱ ╱ ◣ ▁▄▆ 吧!╲ ╲
╱╱ ╱ ◤ ◤` ◢ ▏ ╲ ╲╲
ψraepopo ∕ / /│▉ ▊ ▆▆ 6▏ ▎│ \ \ ﹨ ╲
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.124.61.111
→
09/05 14:25, , 1F
09/05 14:25, 1F
→
09/05 14:25, , 2F
09/05 14:25, 2F