How Do You Upload And Download Images And File From Database?

Mar 7, 2008

Hi,


how do i upload and download images and files from database row?
is there anyway i can upload images so that uploaded images ares saved in a listbox and at the same time in the IMAGES folder
in the solution explorer as well so that i can later select an image from
listbox and download it when needed? 
i m using c#,vwd2005 express,sql express.


thanks.


jack.

View 38 Replies


ADVERTISEMENT

Upload (or Download) A File Into (or From) A MS SQL Server DB

Feb 6, 2006

I would like to design a content-management feature on a website, in particularbe able to upload a binary file and to store it into a MS Sql Server DB.be able to download it afterwards. The sizes of the files are very limited (less than 100Kb) so I do not need any special feature to handle the upload/download.Does anyone know how to achieve such feature?Thanks in advance,Joannes

View 5 Replies View Related

Need To Upload Images To Database - Help

May 30, 2008

Hia,

We have a simple table which we need to store logo's for a website. The table looks like this:

CLIENTLOGO (Tablename)
id (Bigint) (PK) - NOT NULL
StoredImage (Image) - NOT NULL
ImageSize (Integer) - NULL

Im not an expert on sql sorry!

I have two problems,
1. I need to upload some logo's (they are gif's if thats important)
2. I need to store the image size

I don't have a clue how to do 2 but ive tried the following for 1 but it doesnt seem to work

Insert into CLIENTLOGO (id, storedImageTablename)
Values (1, 'c:ClientLogo1.gif')

Can somebody help, im really confused about this one

View 4 Replies View Related

Shared Hosting - How Do You Upload/download Your Database?

Apr 27, 2006

Hello,

I am an ASP.NET 2.0/SQL 2005 web developer, and I have run into a huge frustration for some time now that I can't seem to get past. My goal is to develop SQL databases for my costomers on my development machine, and then upload the completed database out to my host. I have not found a host that allows this yet. Some hosts do not allow remote SQL connections altogether, and the best hosts I have been able to find allow remote SQL connections, but do not allow SSIS or DTS packages to run to transfer database objects to the production server.

What does this mean? Well, I have to manually transfer or recreate individual stored procedures and recreate primary, foreign, and other table constraints. I cannot just run a DTS package to transfer the completed objects. So this means duplicating effort, changes for mistakes, and more server downtime during site upgrades. I have called so many host providers, and I haven't found one that can get me past this.

Also, I contacted Microsoft to ask about Licensing (thinking I would just lease a dedicated server), and the only option I can use is SPLA licensing. The catch, I have to lease the OS through SPLA as well, and all the hosts I have contacted put the OS on the server themselves. This means I would be paying for the OS twice.

Ideally, I would just love to find a shared web host package that I could use efficiently with my SQL development. Am I missing something? If anyone has any advice, please help! I would be so appreciative!!! Thanks.

Regards,

Jeremy

View 5 Replies View Related

Upload Images And Text To Database

Mar 22, 2008

 I have a form that inserts text and also allows the user to upload 3 images.  I have the text part working, but can't figure out how to get the images uploaded. Here is the form.  I just inserted the 3 upload controls in the form and in the datasource to show what I am trying to do.  If anybody can help me I appreciate it.   1 <h3><br />Add Listing</h3><hr />
2 <div style="margin:auto;">
3 <table align="center" >
4 <tr>
5 <td align="right">
6 Address:</td>
7 <td>
8 <asp:TextBox ID="TbAddress" runat="server" MaxLength="62" Width="250px"></asp:TextBox> </td>
9 </tr>
10 <tr>
11 <td align="right">
12 City:</td>
13 <td align="left">
14 <asp:TextBox ID="TbCity" runat="server" MaxLength="62" Width="250px"></asp:TextBox></td>
15 </tr>
16 <tr>
17 <td align="right">
18 State:</td>
19 <td align="left">
20 <asp:DropDownList ID="DdState" runat="server">
21 </asp:DropDownList>
22 </td>
23 </tr>
24 <tr>
25 <td align="right">
26 Zip Code:</td>
27 <td align="left">
28 <asp:TextBox ID="TbZipCode" MaxLength="15" Width="75px" runat="server"></asp:TextBox>
29 </td>
30 </tr>
31
32 <tr>
33 <td align="right">
34 Listing Price:</td>
35 <td align="left">
36 <asp:TextBox ID="TbListingPrice" runat="server" MaxLength="30" Width="125px"></asp:TextBox></td>
37 </tr>
38 <tr>
39 <td align="right">
40 Taxes/Half:</td>
41 <td align="left">
42 <asp:TextBox ID="TbTaxes" runat="server" MaxLength="30" Width="125px"></asp:TextBox></td>
43 </tr>
44 <tr>
45 <td align="right">
46 Subdivision:</td>
47 <td align="left">
48 <asp:TextBox ID="TbSubdivision" runat="server" MaxLength="60" Width="225px"></asp:TextBox></td>
49 </tr>
50 <tr>
51 <td align="right">
52 County:</td>
53 <td align="left">
54 <asp:TextBox ID="TbCounty" runat="server" MaxLength="60" Width="225px"></asp:TextBox></td>
55 </tr>
56 <tr>
57 <td align="right">
58 School District:</td>
59 <td align="left">
60 <asp:TextBox ID="TbSchoolDistrict" runat="server" MaxLength="60" Width="225px"></asp:TextBox></td>
61 </tr>
62 <tr>
63 <td align="right">
64 Bedrooms:</td>
65 <td align="left">
66 <asp:DropDownList ID="DdBedrooms" runat="server">
67 </asp:DropDownList>
68 </td>
69 </tr>
70 <tr>
71 <td align="right">
72 Bathrooms:</td>
73 <td align="left">
74 <asp:DropDownList ID="DdBathrooms" runat="server">
75 </asp:DropDownList>
76 </td>
77 </tr>
78 <tr>
79 <td align="right">
80 Living Space:</td>
81 <td align="left">
82 <asp:TextBox ID="TbLivingSpace" runat="server" MaxLength="30" Width="125px"></asp:TextBox></td>
83 </tr>
84 <tr>
85 <td align="right">
86 Stories:</td>
87 <td align="left">
88 <asp:DropDownList ID="DdStories" runat="server">
89 </asp:DropDownList>
90 </td>
91 </tr>
92 <tr>
93 <td align="right">
94 Building Style:</td>
95 <td align="left">
96 <asp:TextBox ID="TbBuildingStyle" runat="server" MaxLength="60" Width="225px"></asp:TextBox></td>
97 </tr>
98 <tr>
99 <td align="right">
100 Year Built:</td>
101 <td align="left">
102 <asp:TextBox ID="TbYearBuilt" runat="server" MaxLength="30" Width="125px"></asp:TextBox></td>
103 </tr>
104 <tr>
105 <td align="right">
106 Bastment:</td>
107 <td align="left">
108 <asp:DropDownList ID="DdBasement" runat="server">
109 </asp:DropDownList>
110 </td>
111 </tr>
112 <tr>
113 <td align="right">
114 Heating:</td>
115 <td align="left">
116 <asp:DropDownList ID="DdHeating" runat="server">
117 </asp:DropDownList>
118 </td>
119 </tr>
120 <tr>
121 <td align="right">
122 Cooling:</td>
123 <td align="left">
124 <asp:DropDownList ID="DdCooling" runat="server">
125 </asp:DropDownList>
126 </td>
127 </tr>
128 <tr>
129 <td align="right">
130 Image 1:</td>
131 <td align="left">
132
133 <asp:FileUpload ID="FileUpload1" runat="server" />
134 </td>
135 </tr>
136 <tr>
137 <td align="right">
138 Image 2:</td>
139 <td align="left">
140 <asp:FileUpload ID="FileUpload2" runat="server" />
141 </td>
142 </tr>
143 <tr>
144 <td align="right">
145 Image 3:</td>
146 <td align="left">
147 <asp:FileUpload ID="FileUpload3" runat="server" />
148 </td>
149 </tr>
150 <tr>
151 <td>
152 &nbsp;</td>
153 <td>
154 &nbsp;</td>
155 </tr>
156 <tr>
157 <td align="right">
158 <asp:Button ID="Button1" runat="server" Text="Save" />
159 </td>
160 <td>
161 &nbsp;</td>
162 </tr>
163
164
165 </table>
166
167 </div>
168
169
170 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:treesConnectionString %>"
171 InsertCommand="INSERT INTO SueHorvath(Address, City, State, ZipCode, ListPrice, Taxes, Subdivision, County, SchoolDistrict, Bedrooms, Bathrooms, LivingSpace, Stories, BuildingStyle, YearBuilt, Basement, Heating, Cooling, Image1, Image2, Image3) VALUES (@Address, @City, @State, @ZipCode, @ListPrice, @Taxes, @Subdivision, @County, @SchoolDistrict, @Bedrooms, @Bathrooms, @LivingSpace, @Stories, @BuildingStyle, @YearBuilt, @Basement, @Heating, @Cooling, @Image1, @Image2, @Image3)" >
172 <InsertParameters>
173 <asp:ControlParameter Name="Address" Type="String"
174 ControlID="TbAddress" />
175 <asp:ControlParameter Name="City" Type="String"
176 ControlID="TbCity" />
177 <asp:ControlParameter Name="State" Type="String"
178 ControlID="DdState" />
179 <asp:ControlParameter Name="ZipCode" Type="String"
180 ControlID="TbZipCode" />
181 <asp:ControlParameter Name="ListPrice" Type="String"
182 ControlID="TbListingPrice" />
183 <asp:ControlParameter Name="Taxes" Type="String"
184 ControlID="TbTaxes" />
185 <asp:ControlParameter Name="Subdivision" Type="String"
186 ControlID="TbSubdivision" />
187 <asp:ControlParameter Name="County" Type="String"
188 ControlID="TbCounty" />
189 <asp:ControlParameter Name="SchoolDistrict" Type="String"
190 ControlID="TbSchoolDistrict" />
191 <asp:ControlParameter Name="Bedrooms" Type="String"
192 ControlID="DdBedrooms" />
193 <asp:ControlParameter Name="Bathrooms" Type="String"
194 ControlID="DdBedrooms" />
195 <asp:ControlParameter Name="LivingSpace" Type="String"
196 ControlID="TbLivingSpace" />
197 <asp:ControlParameter Name="Stories" Type="String"
198 ControlID="DdStories" />
199 <asp:ControlParameter Name="BuildingStyle" Type="String"
200 ControlID="TbBuildingStyle" />
201 <asp:ControlParameter Name="YearBuilt" Type="String"
202 ControlID="TbYearBuilt" />
203 <asp:ControlParameter Name="Basement" Type="String"
204 ControlID="DdBasement" />
205 <asp:ControlParameter Name="Heating" Type="String"
206 ControlID="DdHeating" />
207 <asp:ControlParameter Name="Cooling" Type="String"
208 ControlID="DdCooling" />
209
210 <asp:ControlParameter Name="FileUpload1" Type="String"
211 ControlID="FileUpload1" />
212 <asp:ControlParameter Name="FileUpload2" Type="String"
213 ControlID="FileUpload2" />
214 <asp:ControlParameter Name="FileUpload3" Type="String"
215 ControlID="FileUpload3" />
216
217
218 </InsertParameters>
219
220 </asp:SqlDataSource>
  And here is the code behind   1
2 Partial Class mylistings
3 Inherits System.Web.UI.Page
4 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
5
6 SqlDataSource1.Insert()
7 TbAddress.Text = ""
8 TbCity.Text = ""
9 DdState.Text = ""
10 TbZipCode.Text = ""
11 TbListingPrice.Text = ""
12 TbTaxes.Text = ""
13 TbSubdivision.Text = ""
14 TbCounty.Text = ""
15 TbSchoolDistrict.Text = ""
16 DdBedrooms.Text = ""
17 DdBathrooms.Text = ""
18 TbLivingSpace.Text = ""
19 DdStories.Text = ""
20 TbBuildingStyle.Text = ""
21 TbYearBuilt.Text = ""
22 DdBasement.Text = ""
23 DdHeating.Text = ""
24 DdCooling.Text = ""
25
26
27
28
29 Response.Redirect(Request.Url.ToString(), False) ' will include the querystring
30 End Sub
31 End Class
32
  

View 7 Replies View Related

How To Upload And Retrieve Images From The Database

Mar 26, 2008

i am using sql server,asp.net and C# language.I am able to upload data into the database but couldnt retrieve it from the database.i am using the following code to upload image into the database.kindly help.
 
 SqlConnection connection = null;         try         {             FileUpload img = (FileUpload)imgUpload;             Byte[] imgByte = null;             if (img.HasFile && img.PostedFile != null)             {                 HttpPostedFile File = imgUpload.PostedFile;                 imgByte = new Byte[File.ContentLength];                 File.InputStream.Read(imgByte, 0, File.ContentLength);             }             string conn = connection establishing string;             connection = new SqlConnection(conn);             connection.Open();             string sql = "insert into imagetable values(@enm, @eimg) SELECT @@IDENTITY";             SqlCommand cmd = new SqlCommand(sql, connection);             cmd.Parameters.AddWithValue("@enm", txtEName.Text.Trim());             cmd.Parameters.AddWithValue("@eimg", imgByte);             int id = Convert.ToInt32(cmd.ExecuteScalar());             lblResult.Text = String.Format("Employee ID is {0}", id);         }         catch         {             lblResult.Text = "There was an error";         }        finally        {            connection.Close();        }

View 9 Replies View Related

How Do I Upload To And Download From A Shared SQL Server 2005 Database?

Dec 13, 2006

My hosting gives me ASP.NET 2.0 and a shared SQL Server 2005 package.
I have Visual Studio 2005 on my machine - which installs SQL Server 2005 Express. I have also installed SQL Server 2005 Management Studio Express.
I wish to develop my database locally (mdf file) as I won't always have internet access (and therefore can't always work directly with the remote shared database).
My question is, how do I upload my database info from my local machine to my remote shared database?
Also I shall wish to download my remote database to my local machine in order to work on the database (and then be able to re-upload it) sometimes.
Please can somebody tell me how I can do this?
Will SQL Server 2005 Management Studio Express permit me to do this and if so how?
If I need the full version of SQL Server 2005 Management Studio then I do have SQL Server 2005 and this install with it (but it all looks a bit complicated to install for me).
Many thanks for all help given,
Graham
 

View 1 Replies View Related

Merge Replication, Subscriber Can Only Download But Not Upload??

Apr 28, 2007

Hi,

I need a urgent help! The problem is that every synchronization only transfer data from subscriber to publisher, but not the other direction. The publisher is sql server 2005 standard edition, and the subscriber is 2005 express. Is that any stored-procedure to deal with such a problem?

Thanks for any commnet.

View 14 Replies View Related

How To Upload Images To SQL2005 (using C#) And Retreive Them

Sep 13, 2007

Hi guys,    I'm creating a webSite and i'd like to save images to my db. I've been using fileUpload to get the image i want to store, but i can't get it right! After "mastering" the storage of my images , i'd like to be able to retrieve them. I allready have SPs created for both storage & retrieval of images!Can anyone help me please? Thanks,superJB

View 3 Replies View Related

Browsing For Files (Images) To Upload To Server

Jun 9, 2007

 How do i Browser for files in computer, and upload them to Server? then link the file's URL(on server) into a Database.What i am wanting to do: Upload pictures (For products) for use in product pages What i think i need: Browse for images on local computerUpload the file to ServerStore the Image URL(relative to server) in DB

View 13 Replies View Related

Adding File Information To SQL Database On File Upload

Apr 18, 2004

Hi there :)

I'm in the final stage of my asp.net project and one of the last things I need to do is add the following file information to my SQL server 2000 database when a file is uploaded:

First of all I have a resource table to which I need to add:
- filename
- file_path
- file_size
(the resource_id has a auto increment value)

so that should hopefully be straight forward when the file is uploaded. The next step is to reference the new resource_id in my module_resource table. My module resource table consists of:
- resource_id (foreign key)
- module_id (foreign key)

So, adding the module_id is easy enough as I can just get the value using Request.QueryString["module_id"]. The bit that I am unsure about is how to insert the new resource_id from the resource table into the module_resource table on file upload. How is this done? Using one table would solve the issue but I want one resource to be available to all modules - many to many relationship.

Any ideas?

Many thanks :)

View 1 Replies View Related

Cannot Upload File To Database

Mar 16, 2006

  Can anyone correct my code?I will like to add a url to my database and upload my image to web server.txtAddTitle will become my title nametxtFileName allow user to type in image name that will upload to webserver and at the meantime will insert into database as url referencesvalue for @chapterid will get from drop down list(ddlLesson) and the index value will store in database.
now i am able to upload my images with the file name that i have given to web server, but I am unable to insert data to my database.
 Sub DoUpload(ByVal Sender As Object, ByVal e As System.EventArgs)        Dim sPath As String        Dim sFile As String        Dim sFullPath As String        Dim sSplit() As String        Dim sPathFriendly As String
              'Upload to same path as script. Internet Anonymous User must have write permissions        sPath = Server.MapPath("../Tutorial")        'sPath = Server.MapPath(".")        If Right(sPath, 1) <> "" Then            sPathFriendly = sPath 'Friendly path name for display            sPath = sPath & ""        Else            sPathFriendly = Left(sPath, Len(sPath) - 1)        End If
        'Save as same file name being posted        'The code below resolves the file name        '(removes path info)        sFile = txtFileName.Text        'sFile = txtUpload.PostedFile.FileName        sSplit = Split(sFile, "")        sFile = sSplit(UBound(sSplit))
        sFullPath = sPath & sFile        Try            txtUpload.PostedFile.SaveAs(sFullPath)            lblResults.Text = "<br>Upload of File " & sFile & " to " & sPathFriendly & " succeeded"
        Catch Ex As Exception
            lblResults.Text = "<br>Upload of File " & sFile & " to " & sPathFriendly & " failed for the following reason: " & Ex.Message        Finally            lblResults.Font.Bold = True            lblResults.Visible = True        End Try
        Dim mycommand As SqlCommand        Dim myConnection As SqlConnection        Message.InnerHtml = ""        'to all the valur to database        If IsValid Then
            myConnection = New SqlConnection("Server=localhost;UID=sa;pwd=;database=u")            mycommand = New SqlCommand("INSERT INTO t_linkTitle(link_chapterid,link_name,link_url) VALUES (@chapterid,@titleName,@titleUrl)", myConnection)
            mycommand.Parameters.Add("@chapterid", SqlDbType.VarChar, 50).Value = ddlLesson.SelectedItem.Value            mycommand.Parameters.Add("@titleName", SqlDbType.VarChar, 50).Value = txtAddTitle.Text            mycommand.Parameters.Add("@titleUrl", SqlDbType.VarChar, 100).Value = txtFileName.Text
            mycommand.Connection.Open()            msgErrorTitle.Style("color") = "OrangeRed"            Try                mycommand.ExecuteNonQuery()                msgErrorTitle.InnerHtml = "New title <b>" + txtAddTitle.Text + "</b> Added to " + "<b>" + ddlLesson.SelectedItem.Text + "</b><br>" + mycommand.ToString()            Catch Exp As SqlException
                If Exp.Number = 2627 Then                    msgErrorTitle.InnerHtml = "ERROR: Title already exists. Please use another title"                Else                    msgErrorTitle.InnerHtml = "ERROR: Could not add record, please ensure the fields are correctly filled out"                End If
            End Try
            mycommand.Connection.Close()        End If
        LoadTitle()
    End Sub

View 2 Replies View Related

How Download File From Database?

Oct 15, 2004

How can I download a file that is previously uploaded to database?
Of course its kind is Byte.

View 1 Replies View Related

Upload File To Database Using Sqldatasource

Sep 12, 2007

Hi,I am trying to upload a file to a database. I have all the code set up but I get this error message: Operand type clash: nvarchar is incompatible with image  The following is the code that I have: 1 If FileUpload1.PostedFile Is Nothing OrElse String.IsNullOrEmpty(FileUpload1.PostedFile.FileName) OrElse FileUpload1.PostedFile.InputStream Is Nothing Then
2 lblInfo.Text = "No file selected"
3 Exit Sub
4 End If
5
6 Dim extension As String = Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower()
7 Dim MIMEType As String = Nothing
8
9 Select Case extension
10 Case ".gif"
11 MIMEType = "image/gif"
12 Case ".jpg", ".jpeg", ".jpe"
13 MIMEType = "image/jpeg"
14 Case ".pdf"
15 MIMEType = "application/pdf"
16 Case ".doc"
17 MIMEType = "application/msword"
18 Case ".swf"
19 MIMEType = "application/x-shockwave-flash"
20 Case ".txt", ".html"
21 MIMEType = "text/plain"
22 Case Else
23 lblInfo.Text = "Invalid file upload"
24 Exit Sub
25 End Select
26
27 Dim imageByte(FileUpload1.PostedFile.InputStream.Length) As Byte
28 FileUpload1.PostedFile.InputStream.Read(imageByte, 0, imageByte.Length)
29
30 sqlInsert = "INSERT INTO Pages (MIMEType, ImageData) VALUES (@MIMEType, @ImageData)"
31 SqlDataSource1.InsertCommand = sqlInsert
32 SqlDataSource1.InsertParameters.Add("MIMEType", MIMEType.ToString.Trim)
33 SqlDataSource1.InsertParameters.Add("ImageData", imageByte.ToString)
34 SqlDataSource1.InsertCommand = sqlInsert
35 SqlDataSource1.Insert()
36 SqlDataSource1.InsertParameters.Clear()I problem happen at line 33. I have tried using sqldatasource1.InsertParameters.add("ImageData", imageByte), it doesn't like it.Please help  

View 2 Replies View Related

Upload A File Onto The Database - Image Datatype

Sep 23, 2005

I am using the image datatype to upload files onto SQL SErver 2000. My
problem is that it seems as though the database is only accepting files
of size 65Kb or less.
What is the best way of resolving this problem?

View 2 Replies View Related

How To Upload A Video File Into Database Using Asp.net2.0

Apr 26, 2007



Hi Pals...

I have a problem that uploading an video file into the database

using asp.net2.0 and sqlserver as database.This is urgent for me .

Please help me any one................

thanks in advance

View 10 Replies View Related

Download File That Is Stored In Sql Server Database

Feb 20, 2007

Hi, I have tried to implement file download option. I can download file which is stored in any folder. Code is...        string filepath = Request.Params["file"].ToString();        string filename = Path.GetFileName(filepath);        Response.Clear();        Response.ContentType = "image/gif";        Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);        Response.Flush();        Response.WriteFile(filepath);This code is working fine. But now I am facing a problem. Files (not the path) are stored in database table. User can download file from the database. How can I do this? The file may be a .txt, .doc, .xls, .jpg or .gif.

View 13 Replies View Related

Question About How To Upload File Into Database(sqlserver Express)?

Jun 28, 2006

I'm a newbie.
I have googled many web sites,but i can't find the help that how to upload or store files(include images) into a database with Asp.Net 2.0.
Although i have found few samples about storing images into database,but the sample applied with Asp.Net 1.0 or 1.1 technology...
In microsoft MSDN,i found the help about FileUpload control,but the sample is about how to upload files to servers's folder with saveas() method.
Who can help me ?Give me a refer sample about upload files  to database with Asp.Net 2.0. Is it need to use stream or what other method?
By the way, i want make a document managment system with vwd and sql express.
Thank u very much if u can give me a help.

View 2 Replies View Related

Images - Store In A Database Or File System?

Jun 19, 2007

I have recently designed and built my first database using SQL server 2005 express. I have included an image (BLOB) column in one of the database tables. This is a bad idea according to some experts, and some say it is OK!


I am currently carrying out a trial with just 3 pictures via Visual Basic 2005 express forms, and there is no problem so far as the images are displayed for each record. But I anticipate between 300 - 1000 images for the table, and this could pose real problems for SQL server 2005 express and Visual Basic 2005 express, I guess.


I have just been reading that the cost of storing large images in the database is too high! I have also read it's better to store images (BLOB) into the file system because it is cheaper to store them no matter how many there are.


But the question is how I can reference an image in this path: C:PictureProductGrocery0052745.jpg in the database table, so that when I select a record Visual Basic 2005 forms the image is displayed accordingly, similar as when stored directly in the database table? Your help very much appreciated.

View 3 Replies View Related

SQL CONNECTION - INSERT - RETRIEVE ID - Rename File - UPLOAD FILE

Sep 15, 2007

Hi there,
I have inherited a databse and am building a new website to go wiht it.
There is a file upload page which will upload images to a directory.  I need to insert into the database retrieve the id just added then upload the image renaming it in the format locID(QueryString)_ImageID(retrieved from database).jpg
The page has a file upload control and a button.
I am trying to write my code behind so that when the button is clicked it inserts location id into the images table retrieves Image id. Renames the file and uploads it to the images folder.
II think i need to call the routine from another routine for the button click but the signatures are different, where am i going wrong? or for that matter have i been pissing into the wind for the last 4 hours?
CODE BEHIND

Imports System.Data
Imports System.Data.SqlClientPartial Class admin_Add_Images
Inherits System.Web.UI.PageProtected Sub UploadImage(ByVal Sender As Object, ByVal e As SqlDataSourceStatusEventArgs)
Dim LocationId As String = Request.QueryString(ID)

' create a new SqlConnectionDim NewConn As New SqlConnection
NewConn = New SqlConnection("server=desktopsqlexpress;uid=xxxxxx;pwd=xxxxxxx;database=MYLOCDEV") 'OleDbConnection i
' open the connection
NewConn.Open()Dim MyInsert = New SqlCommand("INSERT into image([LocationID]) VALUES (@LocationID); SET @NewId = Scope_Identity()")
NewConn.Close()
If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then
'RENAME THE FILEDim newid As Integer = e.Command.Parameters("@NewId").Value
Dim fn As String = (LocationId & "_" & newid & ".jpg")Dim SaveLocation As String = Server.MapPath("oicImages") & "" & fn
Try
File1.PostedFile.SaveAs(SaveLocation)Response.Write("The file has been uploaded.")
Catch Exc As ExceptionResponse.Write("Error: " & Exc.Message)
End Try
ElseResponse.Write("Please select a file to upload.")

End If
End SubProtected Sub Submit1_Click(ByVal Sender As Object, ByVal e As System.EventArgs) Handles Submit1.Click

UploadImage()End Sub
End Class

View 2 Replies View Related

File Upload Help

Dec 11, 2007

Hi, I am trying to upload a file to database.
I have used the following code, every loads good to the database apart from the image, does it go anywhere?
I have created a column in the table called 'FileUploadAdvert' and made it an image?
Any ideas where I'm going wrong?
ThanksGordon 
Protected Sub btnAdvertSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdvertSubmit.ClickDim dashDataSource As New SqlDataSource()dashDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("DashConnectionString1").ToString()
dashDataSource.InsertCommandType = SqlDataSourceCommandType.Text
dashDataSource.InsertCommand = "INSERT INTO tblAdvert (AdvertOwner, AdvertName, TopLeftH, TopLeftV, Height, Width, ToolTip, WebLink, AcceptTerms, DateTimeStamp, IPAddress) VALUES (@AdvertOwner, @AdvertName, @TopLeftH, @TopLeftV, @Height, @Width, @ToolTip, @WebLink, @AcceptTerms, @DateTimeStamp, @IPAddress)"dashDataSource.InsertParameters.Add("AdvertOwner", txtName.Text)
dashDataSource.InsertParameters.Add("AdvertName", txtCompName.Text)dashDataSource.InsertParameters.Add("TopLeftH", DropDownAccross.Text)
dashDataSource.InsertParameters.Add("TopLeftV", DropDownDown.Text)dashDataSource.InsertParameters.Add("Height", DropDownHeight.Text)
dashDataSource.InsertParameters.Add("Width", DropDownWidth.Text)dashDataSource.InsertParameters.Add("ToolTip", txtOver.Text)
dashDataSource.InsertParameters.Add("Weblink", txtURL.Text)dashDataSource.InsertParameters.Add("AcceptTerms", CheckBoxAgree.Checked)
dashDataSource.InsertParameters.Add("IPAddress", Request.UserHostAddress.ToString)dashDataSource.InsertParameters.Add("DateTimeStamp", DateTime.Now)
If Not FileUploadAdvert.PostedFile Is Nothing ThenDim filepath As String = FileUploadAdvert.PostedFile.FileName
Dim pat As String = "\(?:.+)\(.+).(.+)"Dim r As Regex = New Regex(pat)
'runDim m As Match = r.Match(filepath)
Dim file_ext As String = m.Groups(2).Captures(0).ToString()Dim filename As String = m.Groups(1).Captures(0).ToString()
Dim file As String = filename & "." & file_ext
'save the file to the server FileUploadAdvert.PostedFile.SaveAs(Server.MapPath(".") & file)
lblStatus.Text = "File Saved to: " & Server.MapPath(".") & fileEnd If
 Dim rowsAffected As Integer = 0
Try
rowsAffected = dashDataSource.Insert()Catch ex As Exception
Server.Transfer("Register_Fail.aspx")
Finally
dashDataSource = Nothing
End Try
If rowsAffected <> 1 ThenServer.Transfer("Register_Fail.aspx")
ElseServer.Transfer("Register_Complete.aspx")
End If
End Sub

View 4 Replies View Related

File Upload To SQL In 2.0 VB

May 2, 2006

Can anyone give me an example of how to Upload a file to SQL in asp.net 2.0 using VB?
 
Thanks
Randy

View 2 Replies View Related

Upload File

May 5, 2008

Hello

I am using Microsoft SQL Server Management Studio Express and want to insert a row into a table. The table (Pictures) has the following columns: ID (int), Filename (varchar), Data (varbinary).

INSERT INTO Pictures(ID, Filename, Data) VALUES
(12, 'photo.jpg', C:photo.jpg);


The statement above does not work. How do you do it?

Thank you

View 1 Replies View Related

Store A File Upload Into DB

Sep 10, 2007

Can someone please direct me to a discussion on which version of SQL Server allows a file to be stored in a db field and how this is accomplished as well as how the file is then retrieved with asp.net VB from the DBthanksMilton

View 16 Replies View Related

Upload File Only Works For Dbo

Nov 6, 2007

Hi there,
My problem is that the upload works in testing for our asp.net site only for dbo. Being mindful of security, I would prefer not use this account to execute all sp_/sql. One solution could be using impersonation only in the content management system where the uploading is done, this is code in web.config:
  <location path="Manage.aspx">    <system.web>    <identity impersonate="true" userName="dbo" password="****" />      <authorization>        <deny users="?" />      </authorization>    </system.web>  </location>
To do this I would have to change the dbo password as set up by previous employee, not a real dba so not sure of the implications (enough permissions to be dangerous though;). Is the above impersonation ok, or should I redo logins security in sql? Thanks.

View 1 Replies View Related

Upload .xls File To SQL Server

Aug 9, 2005

Here's what I have to do:1. Allow user to locate a .xls file on their machine2. Upload this .xls data into an existing table on a remote SQL ServerI can pull the file from my local machine to another directory on the local machien, but can't figure out have to configure the saveas() to save on the remote db server.It seems you have to save the the db server first on the hard drive, then you can insert the .xls file data into the table.Here's my code so far that works to save on the local machine to another directory on that local machine:Dim getmyFile As HttpPostedFile = myfile.PostedFileIf IsNothing(getmyFile) ThenLabel2.Text = "Please select a file to upload"ElseIf getmyFile.ContentLength = 0 ThenLabel2.Text = "Cannot upload zero length File"ElseDim ServerFileName As String = Path.GetFileName(myfile.PostedFile.FileName)getmyFile.SaveAs("C:TestSaving" & ServerFileName)Label2.Text = "Successful upload to C:TestSaving" & ServerFileNamesCon1.Open()Dim strSQL As StringDim err As IntegerstrSQL = "Insert into ActivityTest Select * FROM OPENROWSET"strSQL &= "('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=D: esting.xls;"strSQL &= "HDR = YES ','SELECT * FROM [Sheet1$]')"Label3.Text = strSQL.ToString()Dim cmd As New SqlCommand(strSQL, sCon1)Trycmd.ExecuteNonQuery()err = "Select @@Error"If err <> 0 ThenLabel4.Text = err.ToString()ElseLabel4.Text = "No Error...line 91!"End IfCatch ex As ExceptionLabel2.Text = "Line 82 Error Updating Table: "Label2.Text &= ex.MessageFinallysCon1.Close()End TryEnd IfThanks for the help in advance!!!!

View 1 Replies View Related

Upload File To A DB In Binary

Apr 20, 2006

Hi have done the following but get the errors at the end, any ideas
 Created a stored procedureALTER PROCEDURE ulfile@upload varchar(200)ASINSERT INTO results(@upload)VALUES (@Upload)RETURN after sitting for two hours I realised I had a comma after (200) then the following in the .cs file using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class Default3 : System.Web.UI.Page{//PostedFile Property of Type HTTPPostedFileint intDocLen = txtFileContents.PostedFile.ContentLength;byte[] Docbuffer = new byte[intDoclen];protected void Page_Load(object sender, EventArgs e){ Stream objStream;//InputStream://Gets a Stream object which points to an uploaded Document; //to prepare for reading the contents of the file.objStream = txtFileContents.PostedFile.InputStream;objStream.Read(Docbuffer, 0, intDocLen);//results is the connection objectcmdUploadDoc = new SqlCommand("ulfile", results);cmdUploadDoc.CommandType = CommandType.StoredProcedure;//Add the Params which in the Stored Proc cmdUploadDoc.Parameters.Add("@upload ", SqlDbType.VarChar, 200);//Set Params ValuescmdUploadDoc.Parameters[0].Value = txtTitle.Text;//Set the "@Doc" Param to be Docbuffer byet ArraycmdUploadDoc.Parameters[1].Value = Docbuffer;cmdUploadDoc.Parameters[2].Value = strDocType; }private void btnSubmit_Click(object sender, System.EventArgs e){string strDocExt;//strDocType to store Document type which will be Stored in the Databasestring strDocType;//Will be used to determine Document lengthint intDocLen;//Stream object used for reading the contents of the Uploading DocumnetStream objStream;SqlConnection results;SqlCommand cmdUploadDoc;if(IsValid){if(txtFileContents.PostedFile != null){//Determine File TypestrDocExt = CString.Right(txtFileContents.PostedFile.FileName,4).ToLower();switch(strDocExt){case ".doc":strDocType = "doc";break;case ".ppt":strDocType = "ppt";break;case ".htm":strDocType = "htm";break;case ".html":strDocType = "htm";break;case ".jpg":strDocType = "jpg";break;case ".gif":strDocType = "gif";break;case ".im":strDocType = "im";break;default:strDocType = "txt";break;}//Grab the Content of the Uploaded DocumentintDocLen = txtFileContents.PostedFile.ContentLength;//buffer to hold Document Contentsbyte[] Docbuffer = new byte[intDocLen];//InputStream://Gets a Stream object which points to an uploaded Document; //to prepare for reading the contents of the file.objStream = txtFileContents.PostedFile.InputStream;//Store the Content of the Documnet in a buffer//This buffer will be stored in the DatabaseobjStream.Read(Docbuffer ,0,intDocLen);//Add Uploaded Documnet to Database as Binary//You have to change the connection stringBooksConn = new SqlConnection("Server=66.179.84.110;UID=******;PWD=******;Database=******");//Setting the SqlCommandcmdUploadDoc = new SqlCommand("ulfile",results);cmdUploadDoc.CommandType = CommandType.StoredProcedure;cmdUploadDoc.Parameters.Add("@upload ",SqlDbType.VarChar,200);cmdUploadDoc.Parameters[0].Value = txtTitle.Text;cmdUploadDoc.Parameters[1].Value = Docbuffer ;cmdUploadDoc.Parameters[2].Value = strDocType;Results.Open();cmdUploadDoc.ExecuteNonQuery();Results.Close();}//End of if(txtFileContents.PostedFile != null)}//End Of if(IsValid)}//End of Method btnSubmit_Click}  And the form code <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"><title>Untitled Page</title></head><body><form id="frmUpload" method="post" enctype="multipart/form-data" runat="server"><span>Title</span><asp:textbox id="txtTitle" runat="server" EnableViewState="False"></asp:textbox><asp:requiredfieldvalidator id="valrTitle" runat="server" ErrorMessage="* Required" ControlToValidate="txtTitle">* Required</asp:requiredfieldvalidator><span>Document to Upload</span><input id="txtFileContents" type="file" runat="server" name="txtFileContents"></></><asp:button id="btnSubmit" Text="Submit" Runat="server" OnClick="btnSubmit_Click"></asp:button>   </form></body></html>  however when I try and view in browser I get the following Line 21:
Line 22:
Line 23: Stream objStream;
Line 24: //InputStream:
Line 25: //Gets a Stream object which points to an uploaded Document;  I have trawlled the net, MSDN and anywhere else I can find to see what it is and nothing. eventually changed  Stream.objstream to System.IO.Stream objStream; And now getting the following error Line 29:
Line 30: //results is the connection object
Line 31: cmdUploadDoc = new SqlCommand("ulfile",results);
Line 32: cmdUploadDoc.CommandType = CommandType.StoredProcedure;
Line 33: //Add the Params which in the Stored Proc  Can anyone help?

View 2 Replies View Related

File Upload To SQL Server 6.5 Using Bcp

Jul 15, 1999

Hi,

I am having a problem when I upload a text file to SQL Server 6.5 with bcp utility. The special Chararcter like copy right, registreted etc are not getting uploaded as the same. Its being displayed as a different character when I fire select query from the database.
eg

CIM® is getting uploaded as CIM«

Please help.

Thanks in advance..

View 1 Replies View Related

What Is The Best Way To Upload Huge File Into SQL 2K

Mar 13, 2002

I have a 2 GB text file(semicolon delimited), which I need to
pump into SQL 2K. What is the best way to achieve this in shortest time?

I tried with DTS BCP, it tooks 1 minute 14 secs to transfer 13457 records. This is only 1/2000 of the record i need to transfer. Please help.

Thanks.

regards,
Terry

View 2 Replies View Related

Upload File To Sql Server

Mar 9, 2004

I got some problem in uploading file into the sql server used ASP.
There is no error occur but the file can't be upload into the database.

This is the connection to the sql server:
function GetConnection()
dim Conn
Conn.Provider = "SQLOLEDB"
Conn.Open "Server=(Local);Database=userinfo", "sa", "sa"
set GetConnection = Conn
end function

function CreateUploadTable(Conn)
dim SQL
SQL = SQL & "CREATE TABLE Upload ("
SQL = SQL & "UploadID int IDENTITY (1, 1) NOT NULL ,"
SQL = SQL & "UploadDT datetime NULL ,"
SQL = SQL & "RemoteIP char (15) NULL ,"
SQL = SQL & "ContentType char (64) NULL ,"
SQL = SQL & "SouceFileName varchar (255) NULL ,"
SQL = SQL & "Title varchar (255) NULL ,"
SQL = SQL & "Description text NULL ,"
SQL = SQL & "Data image NULL "
SQL = SQL & ")"
Conn.Execute SQL
end function

function DBSaveUpload(Fields)
dim Conn, RS
Set Conn = GetConnection

Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "Upload", Conn, 2, 2
RS.AddNew
RS("UploadDT") = Now()
RS("RemoteIP") = Request.ServerVariables("REMOTE_ADDR")
RS("ContentType") = Fields("DBFile").ContentType
RS("SouceFileName") = Fields("DBFile").FileName
RS("DataSize") = Fields("DBFile").Value.Length

RS("Description") = Fields("Description").Value.String
RS("Title") = Fields("Title").Value.String
if IncludeType=1 then'For ScriptUtilities
RS("Data").AppendChunk Fields("DBFile").Value.ByteArray
Else'For PureASP upload - String is implemented as method.
RS("Data").AppendChunk MultiByteToBinary(Fields("DBFile").Value.ByteArray)
End If

RS.Update
RS.Close
Conn.Close
DBSaveUpload = "Upload has been successfull"
end function

Pls help me!

View 1 Replies View Related

HTTP File Upload

Aug 11, 2006

I'm looking for a way with Integration Services in SQL'05 to upload a file. How could I do this? Is there any examples out there?

This partuclar HTTP Server has WEBDAV configured so if I could just point to the URL location and new FILE that would be excellent.

Thanks

View 2 Replies View Related

XLSX File Upload

Oct 23, 2007

Hi,



I uploaded an xlsx file to my reporting services. When i click on the xlsx file link in the reporting services frontend, a internet explorer window is opened with the xlsx file information (reporting services) and the xlsx file is opened by the excel application.



Is there any way to prevent the Internet explorer window to be opened?


Regards.

View 4 Replies View Related

Upload And Save A PDF File Into MS SQL Databse

Apr 13, 2007

Hi guys,
 I want to update a PDF file and store it in the MSSQL database. (I know it is better if I save the file on server and just store the link to it, but I have to store the file on the database "Project Requirements")
I would probably use FileUpload control to upload the file. but would I upload it to server temporarly and then save it or would I just upload it to DB.
I appreciate your help and suggestions and any tips & tricks or issue that I have to consider.
Regards,Mehdi

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved