سلام دوستان. من وقی عکس رو توی دیتابیس ذخیره می کنم، می خوام که عکس رو ویرایش کنم اررور میده. من تکه کدهایی که ازش استفاده کردمو می ذارم.
با تشکر
Public Function Convert_Image_From_Byte(ByVal strinput As Byte()) As Image
newMstream = New MemoryStream(CType(strinput, Byte()))
Return Image.FromStream(newMstream)
End Function
Public Function Get_Image_Byte(ByVal StrAddress As String) As Byte()
imgByte = Nothing
stream = New FileStream(StrAddress, FileMode.Open)
reader = New BinaryReader(stream)
imgByte = reader.ReadBytes(stream.Length)
stream.Close()
Return imgByte
End Function
از این کد هم برای گرفتن عکس از دیتابیس استفاده می کنم:
Public Function GetImage_Edit(ByVal strmeli As String) As Byte()
GetImage_Edit = Nothing
resetConnection()
SQL = String.Format("SELECT * FROM tbl_karmand WHERE K_Meli='{0}'", strmeli)
Comm = New SqlClient.SqlCommand(SQL, Cn)
dread = Comm.ExecuteReader
While dread.Read
imgByte = CType(dread.Item(12), Byte())
Return imgByte
End While
End Function
این کد هم برای ویرایش :
Public Function Edit_Karmand(ByVal K_Name As String, ByVal K_Family As String, ByVal K_Tell As String, ByVal K_Mobile As String, ByVal K_Hesab As String, ByVal K_Kart As String, ByVal K_Address As String, ByVal K_Meli As String, ByVal K_Sabeghe As String, ByVal K_Job As String, ByVal K_Hoghogh As String, ByVal K_Admin As String) As Boolean
resetConnection()
SQL = String.Format("UPDATE tbl_karmand SET K_Name='{0}', K_Family='{1}', K_Tell='{2}', K_Mobile='{3}', K_Hesab='{4}', K_Kart='{5}', K_Address='{6}', K_Sabeghe='{8}', K_Job='{9}', K_Hoghogh='{10}', K_Admin='{11}', K_Img='{12}' WHERE K_Meli='{7}'", K_Name, K_Family, K_Tell, K_Mobile, K_Hesab, K_Kart, K_Address, K_Meli, K_Sabeghe, K_Job, K_Hoghogh, K_Admin, "@pic")
Comm.CommandText = SQL
Comm.Parameters.Add("@pic", imgByte)
Comm.CommandType = CommandType.Text
Comm.Connection = Cn
Try
Comm.ExecuteNonQuery()
Comm.Dispose()
Cn.Close()
Return True
Catch ex As Exception
Cn.Close()
Return False
End Try
End Function
این کد هم برای اضافه کردن(که مشکلی نداره)
Public Function Add_Karmand(ByVal K_Name As String, ByVal K_Family As String, ByVal K_Tell As String, ByVal K_Mobile As String, ByVal K_Hesab As String, ByVal K_Kart As String, ByVal K_Address As String, ByVal K_Meli As String, ByVal K_Sabeghe As String, ByVal K_Job As String, ByVal K_Hoghogh As String, ByVal K_Admin As String) As Boolean
resetConnection()
SQL = String.Format("INSERT INTO tbl_karmand (K_Name, K_Family, K_Tell, K_Mobile, K_Hesab, K_Kart, K_Address, K_Meli, K_Sabeghe, K_Job, K_Hoghogh, K_Admin, K_Img) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', @Picture)", K_Name, K_Family, K_Tell, K_Mobile, K_Hesab, K_Kart, K_Address, K_Meli, K_Sabeghe, K_Job, K_Hoghogh, K_Admin)
Comm.CommandText = SQL
Comm.Parameters.Add("@Picture", imgByte)
Comm.CommandType = CommandType.Text
Comm.Connection = Cn
Try
Comm.ExecuteNonQuery()
Comm.Dispose()
Cn.Close()
blnIsImage = False
Return True
Catch ex As Exception
strMessage = ex.Message
Return False
Cn.Close()
End Try
End Function
اگه میشه بگید مشکل از کجاست که خطا میده
راستی. اینم اروری که میده