DataSource Controls :: Uploading An Image To A SQL DB Via A Parameter?
Sep 20, 2010
I've got a bit of a problem that I can't figure out. I've got a SQL data source on a create user page that uploads the user data to a SQL database when the person creating the account clicks the "Next" button. One of the columns in the DB is an "image" data type and I'm using the FileUpload control to do that. Here is the ds and its info on the actual page:
[Code]....
In the code-behind I have the following (it's something I found elsewhere on the web):
[Code]....
The problem is that the following is being thrown when I try to assign 'data' as the 'DefaultValue':
Compiler Error Message: BC30311: Value of type '1-dimensional array of Byte' cannot be converted to 'String'.
I've looked all around the web to try and figure this one out, but all I'm finding are examples of how to do it when a sqldatasource isn't being used. There's gotta be something simple I'm missing, but I'm just not able to figure it out. Incidentally, I don't need to do all that resizing that's in there, I just need to get the image uploaded.
View 2 Replies
Similar Messages:
Jun 7, 2010
I Used AsyncFileUpload(one of Ajac Control Toolkit Controls) to Uploading User's Image. this works well. But i want to change the image url of an image contorl to uploaded image url. how can i perform that? I put Image control in a Update Panel:
[Code]....
in C# code I wrote these:
[Code]....
But it does not work. Image is like Previous. Note that ImageOperations.ResizeFromStream() method resizes and saves the image to a specefic folder. actually I should trigger a Postback to Update the Update Panel but How to do that. I usedUpdatePanelNew.Update(); but it does not work!
View 1 Replies
Mar 22, 2011
in my aspx page i have a file upload control and one image component...i want to display the image uploaded in the image component..
View 4 Replies
Jun 22, 2010
I have a problem about image control. I am using VS2005 in Vista and suddenly uploading and retrieving image to a image control doest not work. I am working with this in Windows XP and all goes fine. After transfering it to vista, I can't upload and retrieve an image stored in the File System. My codes are all the same.
View 19 Replies
Jun 23, 2010
I am uploading images to database....but only error that I am getting at this point when I run it is for.....
DataSource.InsertParameters.Add("MIMEType", MIMEType)
The error for the above line is Object not set to an instance of an Object look over the code an see if you can see what is wrong.
Protected Sub Button_Insert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_Insert.Click
'Make Sure a file has been successfully Uploaded
If FileUpload_Image1.PostedFile Is Nothing OrElse String.IsNullOrEmpty(FileUpload_Image1.PostedFile.FileName) OrElse FileUpload_Image1.PostedFile.InputStream Is Nothing Then
Label_ErrorMessage.Text = "Error"
Else
Label_ErrorMessage.Text = "No Error"
'Exit Sub
End If
'Make sure we are dealing with a JPG or GIF file
Dim extension As String = Path.GetExtension(FileUpload_Image1.PostedFile.FileName).ToLower()
Dim MIMEType As String = Nothing
Select Case extension
Case ".gif"
MIMEType = "Image/gif"
Case ".jpeg", ".jpe"
MIMEType = "Image/jpeg"
Case ".png"
MIMEType = "Image/png"
Case Else
Label_ErrorMessage.Text = "Invalid Type"
'Exit Sub
End Select
Dim DataSource As New SqlDataSource()
DataSource.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ToString
DataSource.InsertCommandType = SqlDataSourceCommandType.Text
DataSource.InsertCommand = "Insert Into ClassifiedImages (Title, DateUploaded, MIMEType, ClassifiedId) Values (@Title, @DateUploaded, @MIMEType, @ClassifiedId)"
DataSource.InsertParameters.Add("Title", "Images For Classified Ad" & " " & Request.QueryString("ClassifiedId"))
DataSource.InsertParameters.Add("DateUploaded", DateTime.Now)
DataSource.InsertParameters.Add("MIMEType", MIMEType)
DataSource.InsertParameters.Add("ClassifiedId", Request.QueryString("ClassifiedId"))
Dim ImageBytes(FileUpload_Image1.PostedFile.InputStream.Length) As Byte
FileUpload_Image1.PostedFile.InputStream.Read(ImageBytes, 0, ImageBytes.Length)
DataSource.InsertParameters.Add("ImageData", ImageBytes.ToString)
Dim RowsAffected As Integer = 0
Try
RowsAffected = DataSource.Insert()
Catch ex As Exception
Response.Redirect("AddImagesProblem.aspx")
End Try
If RowsAffected <> 1 Then
Response.Redirect("AddImagesProblem.aspx")
Else
Response.Redirect("AddImagesSuccess.aspx")
End If
End Sub
View 4 Replies
May 20, 2010
I have several web forms which use a GridView linked to a DataSource control which is defined at design time as follows:
<cc1:pgsqldatasource
id="dsStates"
runat="server"
connectionstring="<%$ ConnectionStrings:PgSqlConnection %>"
oldvaluesparameterformatstring="Original_{0}"
providername="<%$ ConnectionStrings:PgSqlConnection.ProviderName %>" >
</cc1:pgsqldatasource>
As you can see, the connectionstring parameter is defined to a specific connection string name and I need to be able to set such a parameter to a different value, for example, to a session variable content.
View 1 Replies
Oct 27, 2010
I am storing a custom "Organisation" object as a session variable. One of the properties of the Organisation object is "OrganisationID" (integer). I have a DataSource that requires a parameter value to run, and I want to use a SessionParameter to populate this. In a previous version, I stored the OrganisationID directly as a session variable. In that case, I could easily access it like this:
[Code]....
However, how do I now access the OrganisationID property of an "Organisation" type session variable (called "Organisation")? I have tried this, which does not seem to work: <asp:SessionParameter Name="OrganisationID" SessionField="Organisation.OrganisationID" Type="Int32" />
View 2 Replies
Jan 17, 2010
I have built a website using Visual Studio 2008 asp.net 3.5, and data is retreive from a database that is made by SQL Server Management Studio 2008.
The question is: How can I upload the database files to the server? Can you give me a step by step description?!
View 2 Replies
Mar 25, 2010
I need to pass the control parameter to Sql Datasource in code behind,
<asp:ControlParameter ControlID="DDL_RType" Name="rtype" PropertyName="SelectedValue"
View 3 Replies
May 26, 2010
I have a picture that i would like to upload to a database. I am really new to this so i am not sure what to do. I have been using the following code below to upload and retrieve the picture, looks like its uploading ok, but i cant retrieve it. The code i am using comes from this site,
http://www.dotnetcurry.com/%28X%281%29S%28e2mwozemizhla24555f41uzz%29%29/ShowArticle.aspx?ID=129&AspxAutoDetectCookieSupport=1.
Uploading Content to database
try
{
if (cmboTopic.Text == "Blu-Ray Movie")[code].....
View 4 Replies
May 10, 2010
I'm able to upload and read any excel file to my server prior 2007, when I try an 07 Excel file, i'm getting the following error message:
'microsoft.ace.oledb.12.0' provider is not registered on the local machine'
do I need anything specail on the web server to allow for Excel 07 files? I'm running IIS6 and a Win 2003 server
View 1 Replies
Mar 6, 2010
[Code]....
and i found it, here http://forums.asp.net/p/1480079/3451771.aspxi can fairly easily code for a general dbase (name, address, etc..)my question here with this code is...where does my dbase info go?
my dbase info
dbase name = files
tablename = fileTable
column names = fileOne, fileTwo, fileThree
the file upload object is called "fileupload1" and this all goes with a "submit" button
also, that is pretty much for one file, what if the user is uploading more than one file? do i just add more if/then statements, one for each fileupload object?
View 3 Replies
May 12, 2010
post the C# source code for uploading images to a database, and then showing it to the user?? I have tried now for 3 weeks with no luck... Maybe we should recommend to Microsoft to add a file upload html helper method to MVC 3?
View 4 Replies
Jun 28, 2010
I want to upload data from an Excel Sheet into my DB. Now my major requirement is, I do not know the header count in the files to be uploaded and they may vary, for example one file may have 3 headers while some may have 6. and I want data of both these files to go into a single DB. That is, I want to dynamically generate columns in my DB, and store these values. So how do I go about achieving this.
View 4 Replies
Jan 1, 2010
i am looking for some sample code in order to upload and/or retrieve images stored in a database.even the web is full of samples, i was not able to find one without using blobs as i would like to save only the directory of an image when it comes to the place of storing. the reason behind is that i do want to have my database small for some reason and therefore only want to save links to my images inside.
View 5 Replies
Feb 18, 2010
For my web application I need to allow the user to upload a word document to the database. I've searched the forums and I've only been able to find with uploading to a server. Can anyone one give me a link to a tutorial or step by step guide on how to do it? I'm not even sure what data type to set the attribute to in the database.
View 4 Replies
Jan 20, 2010
I creating a page where our clients can view advertising images and then able to download the images in different file formats. So I need the images and the different download types all saved into the same row in the database so that when I go to display them on the page when they select a picture the right download links will be there. So here where my problem comes in, I don't know how to code it so that I can insert mulitiple file paths into the database at once. The images are saved in a table called images. The downloads are saved in a table called Image Downloads.
Here is the code for the page I have it coded to submit the images to the database but not sure how to add the rest. I have got three different sql datasources for each table not sure if that's the way to go.
[Code]....
View 1 Replies
Aug 20, 2010
i am using file upload control for uploading images. in that iam checking the condition,if Image.Width > 250 || Image.Height > 400 then i am resizing the image. but it is giving the error "The SaveAs method is configured to require a rooted path, and the path 'ProductImages/roman_sandals.jpg' is not rooted."
ProductImages is folder where i am saving image. Can anyone find why this is giving error,my code is
string strBigServerPath = AppHardcodeValue.productImgPath;
string strFileName = "";
if (prodImg.HasFile)
{
strFileName = prodImg.PostedFile.FileName;
string uniqueNum = Convert.ToString(System.Guid.NewGuid());
string shortFileName = System.IO.Path.GetFileName(strFileName);
string Extension = System.IO.Path.GetExtension(prodImg.FileName);
string newFileName = shortFileName;
prodImg.SaveAs(Server.MapPath(strBigServerPath + newFileName));
using (System.Drawing.Image Img =
System.Drawing.Image.FromFile(Server.MapPath(strBigServerPath) + newFileName))
{
if (Img.Width > 250 || Img.Height > 400)
{...........................
View 1 Replies
Jan 30, 2010
i want to upload image through folder looping.
code is for that
DirectoryInfo di =new DirectoryInfo ("G:/FICCI/FicciNew/FicciNew/images/Images/AlbumImage");
View 3 Replies
Feb 19, 2010
in my application i am uploading the image into database. before it is store in the database, i want to do image management like decreasing size and decreasing height and width of the image.
View 4 Replies
Jan 8, 2010
I am able to upload an image to a Database from a fileupload control on a detailsview inserting event and then display it again. Here is my code to upload an image from a fileupload control:
Dim UploadedFile2 As FileUpload = CType(DetailsView1.FindControl("Fileupload2"), FileUpload)
Dim extension2 As String = Path.GetExtension(UploadedFile2.PostedFile.FileName).ToLower()
View 2 Replies
Aug 3, 2010
What am i missing or doing wrong here, when i debug, im seeing the selected value in the code behind, but when the page loads, it says the following:
Procedure or function 'Onsite_Report_Procedures' expects parameter '@rptNum', which was not supplied.
<asp:SqlDataSource
ID="SQLOnSiteReport"
runat="server"
ConnectionString="<%$ ConnectionStrings:connectn %>"
SelectCommand="Onsite_Report_Procedures"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="@rptNum" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
[Code]....
View 2 Replies
Aug 4, 2010
I have a stored procedure with output parameter. I encapsulate it with Table Adapter and BLL. Call it using ObjectDataSource in conjuction with formview, just like the one in Data Access Tutorial. How do I get the output parameter in event INSERTED of the ObjectDataSource in code behind (VB)?
My stored procedure looks like this:
[Code]....
My BLL code looks like this:
[Code]....
View 2 Replies
Jul 12, 2010
We have a stored procedure which creates and returns as output the next value in line:
[Code]....
Yes, the dullards who created this system not only failed to use an identity for the primary key of this table, they then proceeded to add 1 to a varchar column to create the new value, thus insuring it can never be anything but numeric.
Sigh. I'm told we cannot address that obvious deficiency now, and we have to leave the column as varchar. Double sigh.
If I execute this sproc from SSMS, the hh_num variable is returned as expected:
[Code]....
However, when I run it through the application, the parameter I set up as output does not get its Value attribute changed:
[Code]....
I've verified that the "@hh_num" maintains its direction and name through the ExecuteNonQuery call, but its Value remains an empty string.
View 1 Replies
Jun 5, 2010
I want to use parameter in SQL command, Which the following code is better and why?
string id= getId();
SqlCommand cmd1 = cn1.CreateCommand();
cmd1.CommandText = " INSERT INTO std(idStd) VALUES (idStd=id) ";
cmd1.ExecuteNonQuery();
string idF = getId();
SqlCommand cmd1 = cn1.CreateCommand();
cmd1.CommandText = " INSERT INTO std(idStd) VALUES (idStd=@id) ";
cmd1.Parameters.AddWithValue(@id, idF);
cmd1.ExecuteNonQuery();
View 3 Replies