2013-03-12 79 views
0

此代碼現在正在工作。我想保存在數據庫中的圖像,請幫助我,我怎麼能在這使用vb.net保存和檢索mysql的圖像

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
     OpenFileDialog1.ShowDialog() 
    TextBox1.Text = OpenFileDialog1.FileName 
    CaptionTextBox.Text = OpenFileDialog1.SafeFileName 

    ' ImagePictureBox.Image = image.FromFile(TextBox1.Text) 
End Sub 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 
    updateRecord("insert into uploadimages(caption,image) values('" + CaptionTextBox.Text + "', '@ImagePictureBox')") 
End Sub 
+0

工作,你的意思是「不是」的工作?什麼是錯誤的(具體的錯誤/結果),你試圖解決什麼問題......「updateRecord」是做什麼的? – 2013-03-12 16:27:39

回答

0
 Imports MySql.Data.MySqlClient 
    Imports System.Drawing.Imaging 

    Dim cn As New MySqlConnection 
     Dim con As New MySqlConnection 
     Dim cmd As New MySqlCommand 
     Dim dr As MySqlDataReader 
     Dim da As MySqlDataAdapter 
     Dim dt As New DataTable 
     Dim abc As String 

    private sub from1() 
     cn.ConnectionString = "Server=localhost; user id=root; password=; database = school" 
    cmd.Connection = cn 
      cn.Open() 
    end sub 

Private Sub images() 
     Dim arrImage() As Byte 
     Dim strImage As String 
     Dim myMs As New IO.MemoryStream 
     If Not IsNothing(Me.PictureBox5.Image) Then 
      Me.PictureBox5.Image.Save(myMs, Me.PictureBox5.Image.RawFormat) 
      arrImage = myMs.GetBuffer 
      strImage = "1000" 
     Else 
      arrImage = Nothing 
      strImage = "NULL" 
     End If 
     cmd.CommandText = "INSERT INTO admision(name, photo) VALUES('" & Me.TextBox1.Text & "'," & _ 
           strImage & ")" 

     If strImage = "1000" Then 
      cmd.Parameters.Add(strImage, MySqlDbType.Blob).Value = arrImage 

     End If 

     MsgBox("Data save successfully!") 
     clear() 
     cmd.ExecuteNonQuery() 

     cn.Close() 

    End Sub