TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Goran Bibic
480
2.9k
200.8k
Insert PDF in database c#
Aug 6 2018 1:40 AM
Is this good way?
private
void
Button2_Click(
object
sender, EventArgs e)
//Save pdf in database
{
byte
[] filedata =
null
;
MemoryStream ms =
new
MemoryStream();
filedata = ms.GetBuffer();
axAcroPDF1.src = LocalEncoding.GetString(ms.ToArray());
using
(SqlConnection openCon =
new
SqlConnection(cs))
{
string
saveStaff =
"declare @maxNo integer = 0 select @maxNo = isnull(max(number), 0) from [dbo].[documents]; Set @maxNo=@maxNo+1; INSERT into dbo.documents (number,file_location, pdf_file) VALUES (@maxNo,@file_location,@pdf_file)"
;
using
(SqlCommand querySaveStaff =
new
SqlCommand(saveStaff))
{
querySaveStaff.Connection = openCon;
querySaveStaff.Parameters.Add(
"@file_location"
, SqlDbType.VarChar, 255).Value = file_locationTextBox.Text;
querySaveStaff.Parameters.AddWithValue(
"@pdf_file"
, SqlDbType.VarBinary).Value = filedata;
openCon.Open();
querySaveStaff.ExecuteNonQuery();
openCon.Close();
}
}
}
Reply
Answers (
10
)
Can you explain this code? I am not able to get this?
Header not getting displayed