I have just changed my code a little. I have been working on this for a very long time and can't get it to work. The error im getting is from this line of code.
MyCommand.ExecuteNonQuery()
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.
Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSave.Click
' convert image into bitmap
Dim bmp As New Bitmap(300, 300)
Dim bmpRect As New Rectangle(0, 0, bmp.Width, bmp.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
g.SmoothingMode = SmoothingMode.HighQuality
g.FillRectangle(New Drawing2D.LinearGradientBrush(bmpRect, Color.White, Color.SlateGray, 50), bmpRect)
Dim x, y As Double
For degree As Integer = 0 To 359 Step 15
x = Math.Sin((degree / 180) * Math.PI) * 35 + bmp.Width / 2
y = Math.Cos((degree / 180) * Math.PI) * 35 + bmp.Height / 2
g.DrawEllipse(Pens.Black, New RectangleF(CSng(x) - 50, CSng(y) - 50, 100, 100))
Next
g.DrawString("created by GDI+ &
VB.NET", Font, Brushes.Black, 2, 2)
g.DrawRectangle(Pens.Red, 0, 0, bmp.Width - 1, bmp.Height - 1)
'************************************************* ***********************************
'************************************************* ***********************************
' create a memorystream
Dim ms As MemoryStream = New MemoryStream
' create buffer to hold data
bmp.Save(ms, Imaging.ImageFormat.Jpeg)
Dim buffer(CType(ms.Length, Int32) - 1) As Byte
ms.Position = 0
ms.Read(buffer, 0, CType(ms.Length, Int32))
' connect to the database
Dim SQLConn As SqlConnection = New SqlConnection
SQLConn.ConnectionString = "Data Source=(local);" & _
"Initial Catalog=Justin;" & _
"Integrated Security=SSPI"
SQLConn.Open()
Dim strSQl As String = strSQl = "INSERT INTO [Auto] (ItemImage) VALUES (@MyImage)"
Dim MyCommand As New SqlCommand
MyCommand.CommandText = strSQl
MyCommand.Connection = SQLConn
Dim param As New SqlParameter(("@MyImage"), SqlDbType.Image, buffer.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, buffer)
MyCommand.Parameters.Add(param)
MyCommand.ExecuteNonQuery()
SQLConn.Close()
bmp.Dispose()
End Sub
End Class