Convert Image and Save into Database
Convert Image and Save into Database
Convert Image and Save into Database
Convert Image and Save into Database
Convert Image and Save into Database
Convert Image and Save into Database Convert Image and Save into Database Convert Image and Save into Database Convert Image and Save into Database Convert Image and Save into Database Convert Image and Save into Database Convert Image and Save into Database Convert Image and Save into Database
Convert Image and Save into Database Convert Image and Save into Database
Convert Image and Save into Database
Go Back  Xtreme Visual Basic Talk > > > Convert Image and Save into Database


Reply
 
Thread Tools Display Modes
  #1  
Old 06-29-2011, 02:22 AM
sp33dy sp33dy is offline
Newcomer
 
Join Date: Jun 2011
Posts: 10
Default Convert Image and Save into Database


Hallo Community,

i´m a new developer and i would like to upload a File with the Fileupload-Control to a MSSQL 2005 Database. I use Visual Studio 2010 an VB.NET

I have also wirte a Code, but i get a Error-Message if i klick die Upload-Butten. "The Website is not available"

Can anybody help me please? Why the error-message cam? or can i optimize the code more? Please help me

My Code:

vbnet Code:
Public Function InsertUpdateData(ByVal cmd As SqlCommand) As Boolean 'Verbindung zur Datenbank herstellen Dim con As New SqlConnection("Data Source=msdehqc01013;Initial Catalog=ReSysDoku;User ID=Re;Password=Co") cmd.CommandType = CommandType.Text cmd.Connection = con Try con.Open() cmd.ExecuteNonQuery() Return True Catch ex As Exception Response.Write(ex.Message) Return False Finally con.Close() con.Dispose() End Try End Function Protected Sub ASPxButten1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ASPxButton1.Click 'Wenn Datei ausgewählt, dann diese uploaden If FileUpload1.HasFile Then ' Datei lesen und in ein ByteArray schreiben Dim filePath As String = FileUpload1.PostedFile.FileName Dim filename As String = Path.GetFileName(filePath) Dim filetype As String = Path.GetExtension(filename) 'Wenn ausgewählte Datei ein JPG oder GIF Format hat, in Datenbank einfügen. If filetype.ToUpper = ".JPG" Or filetype.ToUpper = ".GIF" Then Dim fs As Stream = FileUpload1.PostedFile.InputStream Dim br As New BinaryReader(fs) Dim bytes As Byte() = br.ReadBytes(fs.Length) 'INSERT INTO TABLE ABSUserUpload Dim strQuery As String = "INSERT INTO [ReSysDoku].[dbo].[ABSUserUpload]" _ & "(FileName, FileImage, FileType)" _ & " values (@FileName, @FileImage, @FileType)" 'Command-Befehl für den SQL-Server Dim cmd As New SqlCommand(strQuery) cmd.Parameters.Add("@FileName", SqlDbType.VarChar).Value = filename cmd.Parameters.Add("@FileImage", SqlDbType.Binary).Value = bytes cmd.Parameters.Add("@FileType", SqlDbType.VarChar).Value = filetype 'Connection und übergabe zu dem SQL-Server InsertUpdateData(cmd) ASPxLbl1.Text = "Upload erfolgreich" Else ASPxLbl1.Text = "Falsches Format" End If Else ASPxLbl1.Text = "Wählen Sie eine Datei aus.!" End If

At the moment i check if the filePath, filename and fileType are available, but it also don´t work. I think, thats the problem, if no filename value then it can not convert to a binary array? I have no more ideas.

Thanks for your help
Reply With Quote
  #2  
Old 06-29-2011, 02:55 AM
PlausiblyDamp's Avatar
PlausiblyDampConvert Image and Save into Database PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

If you stick a breakpoint on the start of the method and step through it where does it fail?
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 06-29-2011, 05:43 AM
sp33dy sp33dy is offline
Newcomer
 
Join Date: Jun 2011
Posts: 10
Default

Now i have check my Code, and if the filepath or filename is value then i would like to print it to a lable, but here is the Problem, i get the same Error-Massage if i value a image and make the Klick-Event. Normely it is simpel, it should be print the paht or name of the Image in the lable, but it is not so, i think the Problem from Klick-Event-Sub is the Start. ?

@PlausiblyDamp

I have try this, but it is not realy work. Also i have no experience by Visual-Studio or VB.net. At first i have a IF-query, but how can i check my code, if there is no Image valued?

Where i set the breakpoint?
Which Funktion i must klick ( Next instruction, single step or Prozedur-step?)

Thanks for help
Reply With Quote
  #4  
Old 06-29-2011, 07:13 AM
PlausiblyDamp's Avatar
PlausiblyDampConvert Image and Save into Database PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

I would personally set the breakpoint on the very first line of the ASPxButten1_Click method, then step through it line by line until I either see it crash (in which case I know exactly where it crashes) or if I notice any values not getting correctly assigned.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #5  
Old 06-29-2011, 07:29 AM
sp33dy sp33dy is offline
Newcomer
 
Join Date: Jun 2011
Posts: 10
Default

Okay, i have debug, and my result is:

I Value a Image and checked the code step by step, but on this code, he crashed:

<body onLoad="javascript:initMoreInfo('infoBlockID');">

Last edited by sp33dy; 06-30-2011 at 01:39 AM.
Reply With Quote
  #6  
Old 06-30-2011, 06:57 AM
sp33dy sp33dy is offline
Newcomer
 
Join Date: Jun 2011
Posts: 10
Default

I have lot of Time, and i find my Problem.

ASPX (Dev-Express) and ASP mixed, it dont work, i mean.

Now i have a new Projekt and only ASP-Controls and it works fine

Now i will read the Image from Database.

Thank you for help
Reply With Quote
  #7  
Old 07-01-2011, 03:47 AM
sp33dy sp33dy is offline
Newcomer
 
Join Date: Jun 2011
Posts: 10
Default

Now i can write and read into and from Database.

I dont need help now

Good by
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Convert Image and Save into Database
Convert Image and Save into Database
Convert Image and Save into Database Convert Image and Save into Database
Convert Image and Save into Database
Convert Image and Save into Database
Convert Image and Save into Database Convert Image and Save into Database Convert Image and Save into Database Convert Image and Save into Database Convert Image and Save into Database Convert Image and Save into Database Convert Image and Save into Database
Convert Image and Save into Database
Convert Image and Save into Database
 
Convert Image and Save into Database
Convert Image and Save into Database
 
-->