PDA

View Full Version : سوال: خطا در مورد ذخیزه عکس در دیتا بیس



farhad85
دوشنبه 15 مهر 1392, 23:55 عصر
با سلام
من این کد زیر رو واسه ذخیره عکس در بانکم نوشتم ولی هنگام لود شدن فرمم یه پیغام بصورت زیر میده؟
منظورش چیه؟ چطور کاری کنم که وقتی فرمم لود میشه دیگه این پیامو نده. ممنونم


111615




Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Public Class Form1
Private strSQL As String
Private con As SqlConnection
Private da As SqlDataAdapter
Private com As SqlCommand
Private ds As DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
con = New SqlConnection("Data Source=localhost;Initial " _
& "Catalog=PhotoBank;Integrated Security=True")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Try
strSQL = "SELECT * FROM Persons"
da = New SqlDataAdapter(strSQL, con)
ds = New DataSet
con.Open()
da.Fill(ds, "Persons")
con.Close()
Me.ListBox1.DataSource = ds.Tables("Persons")
Me.ListBox1.DisplayMember = "FLName"
Me.ListBox1.ValueMember = "PersonID"
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
strSQL = "INSERT INTO Persons (FLName, Photo,PERSONID) VALUES (@FLName, @Photo,@PERSONID)"
Dim ms As New MemoryStream
Me.PictureBox1.Image.Save(ms, Me.PictureBox1.Image.RawFormat)
Dim arrPic() As Byte = ms.GetBuffer
ms.Close()
con.Open()
com = New SqlCommand(strSQL, con)
com.Parameters.Add("@FLName", SqlDbType.NVarChar, 50).Value = Me.TextBox1.Text
com.Parameters.Add("@PERSONID", SqlDbType.NVarChar, 50).Value = Me.TextBox2.Text
com.Parameters.Add("@Photo", SqlDbType.VarBinary).Value = arrPic
com.ExecuteNonQuery()
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Try
strSQL = "SELECT * FROM Persons WHERE PersonID = @PersonID"
da = New SqlDataAdapter(strSQL, con)
da.SelectCommand.Parameters.Add("@PersonID", SqlDbType.Int).Value = _
CInt(Me.ListBox1.SelectedValue)
ds = New DataSet
con.Open()
da.Fill(ds, "Persons")
con.Close()
Dim arrPic() As Byte = CType(ds.Tables("Persons") _
.Rows(0).Item("Photo"), Byte())
Dim ms As New MemoryStream(arrPic)
Me.PictureBox2.Image = Image.FromStream(ms)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim dlgOpen As New OpenFileDialog
With dlgOpen
.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF"
.Title = "انتخاب تصوير"
If .ShowDialog = Windows.Forms.DialogResult.OK Then
Me.PictureBox1.Image = Image.FromFile(.FileName)
End If
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class





[/VB][/VB][/VB][/LTR_INLINE]