作者gbmail (做了好长的梦)
看板Visual_Basic
标题[.NET] BLOB传MySQL资料库
时间Fri Sep 5 12:14:27 2008
请输入专案类型(网站专案或者应用程式专案):应用程式专案
这几天参考了很多范例
但大部分都是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
1F:→ gbmail:参考MySQL网站范例已解决 09/05 14:25