Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | Moving the address bar

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > General IT Discussion
Register FAQ Community Calendar

Upload an image via an SQL connection?
Reply
 
Thread Tools
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
Advertisement
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 17:17.


Server: lithium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum