Wrox Programmer Forums
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 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, 11:45 AM
JLN JLN is offline
Authorized User
 
Join Date: Jul 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help===urgent====

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, 12:07 PM
Authorized User
 
Join Date: Jun 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi JLN

You've created the memory stream, but have not read anything into it.
try

dim ms as MemoryStream = New MemoryStream
bmp.save(ms,imagingformat.Jpeg)
dim buffer(ctype(ms.length, int32)-1 as Byte
ms.position = 0
ms.read(buffer,0,ctype(ms.length,int32)

then your sql parameter will need to say something along these lines
Mycommand.Parameters.Add("@MyImage", SqlDbType.Image, buffer.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, buffer)

Hope this helps


Duncan
 
Old July 7th, 2004, 12:14 PM
JLN JLN is offline
Authorized User
 
Join Date: Jul 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The imagingformat is underlined and says its not declared. Do you know why



' create buffer to hold data
        Dim ms As MemoryStream = New MemoryStream
        bmp.Save(ms, imagingformat.Jpeg)
        Dim buffer(CType(ms.Length, Int32) - 1) As Byte
        ms.position = 0
        ms.Read(buffer, 0, CType(ms.Length, Int32))

 
Old July 7th, 2004, 12:18 PM
Authorized User
 
Join Date: Jun 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

that's a typo it sshould be imaging.format.jpeg



Duncan
 
Old July 7th, 2004, 12:23 PM
JLN JLN is offline
Authorized User
 
Join Date: Jul 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah I got that. One more problem. your

Mycommand.Parameters.Add("@MyImage", SqlDbType.Image, buffer.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, buffer)

I get a blue line that says that an add can't have that may arguments


 
Old July 7th, 2004, 12:30 PM
Authorized User
 
Join Date: Jun 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Sorry I thought the command parameters and the parameters would have the same properties.

I tend to use the parameters collection rather than the commands.

create an object of type sqlparameter like

dim param as new sqlparameter("@myImage", etc.....

then add that parameter to the command object

mycommand.parameters.add(param)

then executenoquery

please note the syntax my not be 100% as I'm not in VS at the moment, i'm doing it from memory



Duncan
 
Old July 7th, 2004, 12:40 PM
JLN JLN is offline
Authorized User
 
Join Date: Jul 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well I cleaned it up alittle but im still gettting an error with my
MyCommand.ExecuteNonQuery() ANYTHING ELSE YOU SEE

 ' 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
        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
        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



 
Old July 7th, 2004, 12:43 PM
Authorized User
 
Join Date: Jun 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

put the whole section of code in a try catch block and catch the exception, this should tell whats wrong

Duncan
 
Old July 7th, 2004, 12:47 PM
JLN JLN is offline
Authorized User
 
Join Date: Jul 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ewwww, I never used a try catch block before. Sounds useful. Is it simple to add?

 
Old July 7th, 2004, 01:02 PM
JLN JLN is offline
Authorized User
 
Join Date: Jul 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Why would I get an error that says handlExcetion not declared??




Catch ex As Exception
  HandleException(ex)
End Try






Similar Threads
Thread Thread Starter Forum Replies Last Post
urgent deb_kareng ASP.NET 2.0 Professional 1 August 13th, 2007 07:29 AM
it's urgent deb_kareng ASP.NET 2.0 Professional 3 August 7th, 2007 07:40 AM
urgent help yash_coolbuddy_forindia BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 May 7th, 2007 08:40 AM
urgent???????????? nsr35 Beginning VB 6 1 October 3rd, 2005 10:57 AM
urgent ??????????????? nsr35 Pro VB Databases 0 October 3rd, 2005 04:53 AM





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