i tried this code and it works in a separate table as per its design.
Protected Sub btnSaveImage_Click(sender As Object, e As System.EventArgs) Handles btnSaveImage.Click
If FileUpload1.HasFile Then
Dim name As String = FileUpload1.PostedFile.FileName
Dim length As Integer = FileUpload1.PostedFile.ContentLength
Dim imageBytes As Byte() = New Byte(length - 1) {}
Dim imageStream As Stream = FileUpload1.PostedFile.InputStream
imageStream.Read(imageBytes, 0, length)
Dim connString As String = ConfigurationManager.ConnectionStrings("ImagesDB").ConnectionString
Dim connection As New OleDbConnection(connString)
Dim insertQuery As String = "INSERT INTO Images(ImageName, ImageSize, ImageData) VALUES(@ImageName, @ImageSize, @ImageData)"
Dim command As New OleDbCommand()
command.Connection = connection
command.CommandText = insertQuery
command.CommandType = CommandType.Text
command.Parameters.AddWithValue("@ImageName", name)
command.Parameters.AddWithValue("@ImageSize", length)
command.Parameters.AddWithValue("@ImageData", imageBytes)
Try
connection.Open()
command.ExecuteNonQuery()
lblMessage.Text = "Image data saved successfully"
Catch ex As Exception
lblMessage.Text = "Unable to save image data"
Finally
connection.Close()
End Try
End If
End Sub
in my table i already have table named TAK with following fields. i have a new data insert query through which data is filled by admin. users have permission to update one field named remarks and upload document
if required . if it is not required document may not be uploaded.
it means in all cases the documents are not required and in some cases supporting documents may uploaded.
Code is in VB
Table structure is as under
id letter date remarks
My update query is as under
Dim sql_ins As String
sql_ins = "Update TAK set Remarks_=? where id=?"
Dim oledbcom As New OleDbCommand(sql_ins, con)
oledbcom.Parameters.Add(New OleDbParameter("@Remarks_", OleDbType.VarChar, 250)).Value = rmktxt.Text
oledbcom.Parameters.Add(New OleDbParameter("@id", OleDbType.Integer, 2)).Value = idtxt.Text
oledbcom.ExecuteNonQuery()
i added a field ImageData
i was not able to incorporate the code which i got
i was not able to incorporate the code which i got
Does the converted code produce an error? If so, what is it? If it doesn't, did you try to understand and incorporate it? If so, what errors did you get?
Protected Sub btnSaveImage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSaveImage.Click
If FileUpload1.HasFile Then
Dim name As String = FileUpload1.PostedFile.FileName
Dim length As Integer = FileUpload1.PostedFile.ContentLength
Dim imageBytes As Byte() = New Byte(length - 1) {}
Dim imageStream As Stream = FileUpload1.PostedFile.InputStream
imageStream.Read(imageBytes, 0, length)
Dim connString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim connection As New OleDbConnection(connString)
Dim insertQuery As String = "update TAK set ImageData=? where id=?"
Dim command As New OleDbCommand()
command.Connection = connection
command.CommandText = insertQuery
command.CommandType = CommandType.Text
command.Parameters.AddWithValue("@ID", name)
command.Parameters.AddWithValue("@ImageData", imageBytes)
Try
connection.Open()
command.ExecuteNonQuery()
lblMessage.Text = "Image data saved successfully"
Catch ex As Exception
lblMessage.Text = "Unable to save image data"
Finally
connection.Close()
End Try
End If
End Sub
There is no error . message shows that ' image data saved successfully'
i removed the @ from my code and then it saved the file to access database. Screenshot of the database rable is as under
i want to show this saved file in another page in a gridview.
I made a gridview with data source with code select * from TAK the grid view is not showing the image it shows System.Byte[] in the filed named imagedata
You need to use a handler file to serve requests for images stored in a database. It should implement IHttpHandler. The article I linked to explains this.
the link provided in the post is quiet different. In my access database there is a table named TAK with following fields
id letter date remarks documents
all data except remarks and document is fed by admin
remarks and documents are fed by users. in some cases the document will be not uploaded and in some cases the document will be uploaded. (depends on the requirement)
in the above sample the images are displayed in labels
i am displaying the data in gridview and i want to make a link the the place where document is uploaded.
Member
297 Points
1171 Posts
store files in access database
Sep 25, 2014 11:50 AM|Baiju EP|LINK
in my asp.net+vb web with access database there is a table named TAK with following fields
id letter date remarks
i want to add one more field so that at least one file can be stored in it
All-Star
194032 Points
28035 Posts
Moderator
Re: store files in access database
Sep 25, 2014 12:08 PM|Mikesdotnetting|LINK
You need to use the OLE Object data type. I've written about storing files in Access here: http://www.mikesdotnetting.com/Article/123/Storing-Files-and-Images-in-Access-with-ASP.NET
Member
297 Points
1171 Posts
Re: store files in access database
Sep 27, 2014 10:19 AM|Baiju EP|LINK
i tried to convert it to vb but not able to do through http://converter.telerik.com/ it gives error
All-Star
194032 Points
28035 Posts
Moderator
Re: store files in access database
Sep 27, 2014 03:34 PM|Mikesdotnetting|LINK
Which part of your conversion gives an error? And what is the error?
Member
297 Points
1171 Posts
Re: store files in access database
Sep 27, 2014 11:28 PM|Baiju EP|LINK
i tried this code and it works in a separate table as per its design.
in my table i already have table named TAK with following fields. i have a new data insert query through which data is filled by admin. users have permission to update one field named remarks and upload document if required . if it is not required document may not be uploaded.
it means in all cases the documents are not required and in some cases supporting documents may uploaded.
Code is in VB
Table structure is as under
id letter date remarks
My update query is as under
i added a field ImageData
i was not able to incorporate the code which i got
All-Star
194032 Points
28035 Posts
Moderator
Re: store files in access database
Sep 28, 2014 04:14 AM|Mikesdotnetting|LINK
Member
297 Points
1171 Posts
Re: store files in access database
Sep 28, 2014 04:57 AM|Baiju EP|LINK
The code i tries is as under.
There is no error . message shows that ' image data saved successfully'
but image is not saved to field
All-Star
35159 Points
9075 Posts
Re: store files in access database
Sep 28, 2014 09:20 AM|smirnov|LINK
OleDb Parameters are recognised by their position, not by their name.
So you should have
and not vice versa because you have
"update TAK set ImageData={1} where id={2}"
@-sign is also not required.
See here for more details: http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access
P.S.
If does not work - make sure the record with ID={name} exists because you are doing an update and not insert.
Member
297 Points
1171 Posts
Re: store files in access database
Sep 28, 2014 12:06 PM|Baiju EP|LINK
i removed the @ from my code and then it saved the file to access database. Screenshot of the database rable is as under
i want to show this saved file in another page in a gridview.
I made a gridview with data source with code select * from TAK the grid view is not showing the image it shows System.Byte[] in the filed named imagedata
All-Star
194032 Points
28035 Posts
Moderator
Re: store files in access database
Sep 28, 2014 12:30 PM|Mikesdotnetting|LINK
You need to use a handler file to serve requests for images stored in a database. It should implement IHttpHandler. The article I linked to explains this.
Member
297 Points
1171 Posts
Re: store files in access database
Sep 28, 2014 12:54 PM|Baiju EP|LINK
i didn't get through
All-Star
35159 Points
9075 Posts
Re: store files in access database
Sep 28, 2014 01:00 PM|smirnov|LINK
You need a handler *.ashx or another webform *.aspx which will request and show binary data.
This question has been answered here many times e.g. http://forums.asp.net/t/1696889.aspx?How+to+display+an+image+from+MS+SQL+image+to+VB+NET+web+page
Also read this article (has both c# and vb) http://www.aspsnippets.com/Articles/Display-Images-from-SQL-Server-Database-using-ASP.Net.aspx
Member
297 Points
1171 Posts
Re: store files in access database
Sep 28, 2014 01:18 PM|Baiju EP|LINK
i had tried this link. but i want to display the document saved in table in gridview alongwith other rows. it may be a link or so.
id letter date remarks Imagedata
All-Star
35159 Points
9075 Posts
Re: store files in access database
Sep 28, 2014 01:39 PM|smirnov|LINK
Please be more specific on your questions.
What link did you try?
What is wrong with example on that link and what is different with your approach?
If suppose you read http://www.aspsnippets.com/Articles/Display-Images-from-SQL-Server-Database-using-ASP.Net.aspx you will find complete example with pictures and code on VB.net.
Member
297 Points
1171 Posts
Re: store files in access database
Oct 04, 2014 11:34 AM|Baiju EP|LINK
the link provided in the post is quiet different. In my access database there is a table named TAK with following fields
id letter date remarks documents
all data except remarks and document is fed by admin
remarks and documents are fed by users. in some cases the document will be not uploaded and in some cases the document will be uploaded. (depends on the requirement)
in the above sample the images are displayed in labels
i am displaying the data in gridview and i want to make a link the the place where document is uploaded.
All-Star
194032 Points
28035 Posts
Moderator
Re: store files in access database
Oct 04, 2014 01:36 PM|Mikesdotnetting|LINK
That often happens. If you are unable to adapt examples on the web to your needs, perhaps you should pay someone to do your development for you.