03-10-22, 08:54 PM
كود :
Public Sub Insert_clore_(ByVal id As Int32, ByVal nam_ As String, ByVal col_ As PictureBox)
Try
If (Con.State And System.Data.ConnectionState.Broken = System.Data.ConnectionState.Broken) Then
Con.Close()
End If
If (Con.State = Global.System.Data.ConnectionState.Closed) Then
Con.Open
End If
Using Cmd As New System.Data.SqlClient.SqlCommand
With Cmd
.Connection = Con
.CommandType = CommandType.Text
.CommandText = "Insert Into clore_ ( id,nam_,col_)values(@id,@nam_,@col_)"
.Parameters.Clear()
.Parameters.AddWithValue("@id", SqlDbType.Int).Value = id
.Parameters.AddWithValue("@nam_", SqlDbType.VarChar).Value = nam_
Dim p As New System.Data.SqlClient.SqlParameter("@col_", SqlDbType.Image)
Using MS As New System.IO.MemoryStream()
Using bmpImage As System.Drawing.Image = New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)
Me.PictureBox1.DrawToBitmap(bmpImage, Me.PictureBox1.ClientRectangle)
bmpImage.Save(MS, System.Drawing.Imaging.ImageFormat.Jpeg)
p.Value = MS.GetBuffer()
End Using
.Parameters.Add(p)
If .ExecuteNonQuery() > 0 Then
MsgBox("تم إضافة السجل بنجاح", MsgBoxStyle.Information, "حفظ")
Else
MsgBox("لم يتم إضافة السجل لسبب غير معروف", MsgBoxStyle.Information, "حفظ")
End If
End Using
End With
End Using
Catch ex As Exception
MsgBox(ex.Message)
Finally
Con.Close()
End Try
End Sub