View Single Post
Old 15-04-2004, 22:16   #1
Juan
Inactive
 
Join Date: Dec 2003
Location: Wales
Posts: 148
Juan is an unknown quantity at this point
Question Re: More SQL help needed

Any1 here know how to upload an image via an SQL connection onto a database held on SQL Server 2000? Any help would be very much appreciated. Here's the code I have so far:

Imports System.Data.SqlClient
Imports System.IO

PublicClass Form1
Inherits System.Windows.Forms.Form
'Declare a DataReader Object
Private objDR As SqlDataReader

PrivateSub Form1_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMyBase.Load
'Open the SQLConnection object
SqlConnection1.Open()
'Create the Datareader Object
objDR = SqlCommand1.ExecuteReader()
EndSub


UPLOAD BUTTON CODE


Private
Sub Upload_Button_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Upload_Button.Click
Dim SQLreturn AsInteger

Dim fsimage As System.IO.FileStream = New System.IO.FileStream(File_TextBox.Text, System.IO.FileMode.Open, System.IO.FileAccess.Read)

Dim Picture(fsimage.Length) AsByte
fsimage.Read(Picture, 0, fsimage.Length)

Try
SqlConnection1.Open()
SqlCommand1.Parameters("@pictureTitle").Value = File_TextBox.Text
SqlCommand1.Parameters("@pictureDescription").Valu e = DescriptionBox.Text
SqlCommand1.Parameters("@pictureOwner").Value = System.Environment.UserName
SqlCommand1.Parameters("@pictureData").Value = Picture
SQLreturn = SqlCommand1.ExecuteNonQuery()
'command

Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
SqlConnection1.Close()
EndTry

If SQLreturn <> 1 Then
MessageBox.Show("Could not execute the INSERT query")
'results
Else
MessageBox.Show("INSERT completed successfully")
EndIf
File_TextBox.Clear()

EndSub

Juan is offline   Reply With Quote