Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 7th, 2004, 09:12 AM
JLN JLN is offline
Authorized User
 
Join Date: Jul 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default filling in a buffer

Does anyone know how I fill the buffer. This is my first time dealing with buffers and I can't seem to find the answer.
PLEASE HELP

Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSave.Click
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)


Dim memStrm As New IO.MemoryStream

bmp.Save(memStrm, Imaging.ImageFormat.Jpeg)

Dim buffer() As Byte = memStrm.ToArray()

' connect to the database
Dim SQLConn As SqlConnection = New SqlConnection
Dim strSQl As String = strSQl = "INSERT INTO [Auto] (ItemImage) VALUES (@MyImage)"


SQLConn.ConnectionString = "Data Source=(local);" & _
"Initial Catalog=Justin;" & _
"Integrated Security=SSPI"


Dim MyCommand As New SqlCommand
MyCommand.CommandText = strSQl
MyCommand.Connection = SQLConn

SQLConn.Open()
' Construct INSERT Command


MyCommand.Parameters.Add("@MyImage", SqlDbType.Image, buffer.Length).Value = buffer

MyCommand.ExecuteNonQuery()

SQLConn.Close()
bmp.Dispose()
End Sub



 
Old July 7th, 2004, 01:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

Are you actually having an error with this, and if so, which line or general area is that?

Brian
 
Old July 8th, 2004, 08:06 AM
JLN JLN is offline
Authorized User
 
Join Date: Jul 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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






Similar Threads
Thread Thread Starter Forum Replies Last Post
RESPONSE BUFFER / FLUSH pallone .NET Framework 2.0 3 May 11th, 2008 01:39 PM
Buffer question dparsons ASP.NET 1.0 and 1.1 Professional 0 March 19th, 2006 11:45 PM
flushing buffer in A2K Loralee Access 1 September 26th, 2005 05:44 PM
Buffer Overflow rekha_jsr Oracle 3 February 3rd, 2005 08:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.